Skip to main content

TextEditorBuilder

Trait TextEditorBuilder 

Source
pub trait TextEditorBuilder: Sized {
Show 14 methods // Required methods fn highlight(self, f: impl Fn(&str) -> Vec<TextRun> + 'static) -> Self; fn highlight_limit(self, bytes: usize) -> Self; fn single_line(self) -> Self; fn on_submit(self, f: impl Fn() + 'static) -> Self; fn code(self) -> Self; fn indent(self, spaces: u8) -> Self; fn selection(self, sel: impl Binding<Range<usize>>) -> Self; fn typing_style(self, style: impl Binding<RunStyle>) -> Self; fn base(self, base: Font) -> Self; fn editable<M>(self, v: impl IntoReactive<bool, M>) -> Self; fn no_spellcheck(self) -> Self; fn placeholder<M>(self, t: impl IntoText<M>) -> Self; fn min_lines(self, n: u32) -> Self; fn max_lines(self, n: u32) -> Self;
}
Expand description

Builder methods of TextEditor, reachable through a Decorated (docs/api-style.md “Typed builders and erasure”): generic modifiers and typed ones chain in any order.

Required Methods§

Source

fn highlight(self, f: impl Fn(&str) -> Vec<TextRun> + 'static) -> Self

Live syntax highlighting: f turns the text into runs, and runs again after every edit (and whenever a signal it reads changes). The runs reach the native view as an attributes patch, so the caret and the platform’s undo stack stay put. highlight::highlighter builds f for the languages the crate knows.

Source

fn highlight_limit(self, bytes: usize) -> Self

The size, in bytes, past which TextEditor::highlight leaves the text plain (default HIGHLIGHT_LIMIT, 512 KiB). The tokenizers are linear, but every keystroke restyles the whole document in the native view, and a body of hundreds of thousands of runs is where that stops feeling like typing. A read-only body is styled once and can afford more: raise it there.

Source

fn single_line(self) -> Self

One line, scrolling sideways instead of wrapping: a styled text_field. Enter submits (TextEditor::on_submit) and inserts nothing; a pasted newline becomes a space. For a URL bar or a header value that wants template tags or other runs drawn inline.

Source

fn on_submit(self, f: impl Fn() + 'static) -> Self

What Enter does in a TextEditor::single_line editor (and what a dayscript submit step delivers).

Source

fn code(self) -> Self

Code editing: Tab indents instead of moving focus, Enter keeps the previous line’s indentation (one level deeper after an opening bracket), and an opening bracket or quote gets its closer typed after the caret. Spell-check is off.

Source

fn indent(self, spaces: u8) -> Self

The width of one indentation level in spaces (default 2), for TextEditor::code.

Source

fn selection(self, sel: impl Binding<Range<usize>>) -> Self

Bind the selection, in BYTE offsets into doc.text, two-way: the user moving the caret writes it, and writing it moves the caret. Collapsed when start == end.

Source

fn typing_style(self, style: impl Binding<RunStyle>) -> Self

Bind what the next typed character will be styled with.

The one piece of editor state an app cannot derive from the document and the selection: with a collapsed caret there is no text to read a style off, and “what happens if I type now” is the platform’s own pending state. Writing it is how a toolbar makes the next word bold rather than the last one.

Source

fn base(self, base: Font) -> Self

The style unstyled text draws in, and what relative runs scale against (default Body).

Source

fn editable<M>(self, v: impl IntoReactive<bool, M>) -> Self

Source

fn no_spellcheck(self) -> Self

Hide the platform’s spell-check squiggles (they are on by default); what prose that is not in the system language, or an identifier field, wants. code does this too.

Source

fn placeholder<M>(self, t: impl IntoText<M>) -> Self

Source

fn min_lines(self, n: u32) -> Self

The height band, in lines: never shorter than min_lines, grows to max_lines and then scrolls (0 = unbounded).

Source

fn max_lines(self, n: u32) -> Self

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<DecoratedInner: TextEditorBuilder + Piece> TextEditorBuilder for Decorated<DecoratedInner>

Source§

fn highlight(self, f: impl Fn(&str) -> Vec<TextRun> + 'static) -> Self

Source§

fn highlight_limit(self, bytes: usize) -> Self

Source§

fn single_line(self) -> Self

Source§

fn on_submit(self, f: impl Fn() + 'static) -> Self

Source§

fn code(self) -> Self

Source§

fn indent(self, spaces: u8) -> Self

Source§

fn selection(self, sel: impl Binding<Range<usize>>) -> Self

Source§

fn typing_style(self, style: impl Binding<RunStyle>) -> Self

Source§

fn base(self, base: Font) -> Self

Source§

fn editable<M>(self, v: impl IntoReactive<bool, M>) -> Self

Source§

fn no_spellcheck(self) -> Self

Source§

fn placeholder<M>(self, t: impl IntoText<M>) -> Self

Source§

fn min_lines(self, n: u32) -> Self

Source§

fn max_lines(self, n: u32) -> Self

Implementors§