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§
Sourcefn highlight(self, f: impl Fn(&str) -> Vec<TextRun> + 'static) -> Self
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.
Sourcefn highlight_limit(self, bytes: usize) -> Self
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.
Sourcefn single_line(self) -> Self
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.
Sourcefn on_submit(self, f: impl Fn() + 'static) -> Self
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).
Sourcefn code(self) -> Self
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.
Sourcefn indent(self, spaces: u8) -> Self
fn indent(self, spaces: u8) -> Self
The width of one indentation level in spaces (default 2), for TextEditor::code.
Sourcefn selection(self, sel: impl Binding<Range<usize>>) -> Self
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.
Sourcefn typing_style(self, style: impl Binding<RunStyle>) -> Self
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.
Sourcefn base(self, base: Font) -> Self
fn base(self, base: Font) -> Self
The style unstyled text draws in, and what relative runs scale against (default Body).
fn editable<M>(self, v: impl IntoReactive<bool, M>) -> Self
Sourcefn no_spellcheck(self) -> Self
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.
fn placeholder<M>(self, t: impl IntoText<M>) -> Self
Sourcefn min_lines(self, n: u32) -> Self
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).
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".