pub trait TextInputEditor {
// Provided methods
fn replace_text(
&self,
range: Range<usize>,
text: &str,
options: WriteOptions,
) -> Result<Landed, WriteRefused> { ... }
fn set_selection(
&self,
selection: Range<usize>,
caret_at_start: bool,
) -> Result<(), WriteRefused> { ... }
fn mark_composition(
&self,
range: Range<usize>,
segments: &[CompositionSegment],
) -> Result<(), WriteRefused> { ... }
fn end_composition(&self, origin: ImeOrigin) -> Result<(), WriteRefused> { ... }
fn begin_input_batch(&self) { ... }
fn end_input_batch(&self) { ... }
}Expand description
The half of a text widget’s document a platform’s input system writes
through, beside the TextInputDocument it reads: a TSF text store on
Windows writes under its locks, and reads back at once what it wrote.
A widget hands it out with
TextSurface::input_editor,
None for a field that takes no text. Every method has a default that
refuses or does nothing, so a custom widget that implements none of them
keeps working: the platform treats it as read-only, or takes another path.
§The batch
Writes come between begin_input_batch and
end_input_batch (a TSF lock). Inside it the
widget changes only its own state; every effect the application can
observe (its callbacks, signal writes) is queued, and runs, in order, at
the end of the outermost batch. The batch is also where the writes
outside a composition are grouped into one undo step.
§A composition is a range of text
The input system writes its composition into the document itself, then
marks it (mark_composition); it is not a
preedit the widget inserts and withdraws. While one is marked, writes
change the document without an undo record, and the field’s rules
(filters, a length cap, a single line) wait: they apply to the final text
at end_composition, which records it as one
undo step.
Provided Methods§
Sourcefn replace_text(
&self,
range: Range<usize>,
text: &str,
options: WriteOptions,
) -> Result<Landed, WriteRefused>
fn replace_text( &self, range: Range<usize>, text: &str, options: WriteOptions, ) -> Result<Landed, WriteRefused>
Replace range with text. Outside a composition the field’s rules
apply and what landed is reported; inside one, text lands as given.
A \r\n or a lone \r lands as one line break.
Sourcefn set_selection(
&self,
selection: Range<usize>,
caret_at_start: bool,
) -> Result<(), WriteRefused>
fn set_selection( &self, selection: Range<usize>, caret_at_start: bool, ) -> Result<(), WriteRefused>
Set the selection, the caret at its start when caret_at_start.
Sourcefn mark_composition(
&self,
range: Range<usize>,
segments: &[CompositionSegment],
) -> Result<(), WriteRefused>
fn mark_composition( &self, range: Range<usize>, segments: &[CompositionSegment], ) -> Result<(), WriteRefused>
Mark range of the document as the input system’s composition, drawn
as segments say. The first mark starts the composition (over text
already in the document, for a reconversion, or as an empty range at
the caret); a later one moves or restyles it.
Sourcefn end_composition(&self, origin: ImeOrigin) -> Result<(), WriteRefused>
fn end_composition(&self, origin: ImeOrigin) -> Result<(), WriteRefused>
The composition is over: its text stays, under the field’s rules, as
one undo step, reported as arriving through origin’s channel.
Sourcefn begin_input_batch(&self)
fn begin_input_batch(&self)
Start a batch of writes. Batches nest.
Sourcefn end_input_batch(&self)
fn end_input_batch(&self)
End a batch of writes; at the end of the outermost one, what the batch queued runs.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".