TextEditingController
Shared editing handle with every read, write, movement, and IME method.
Cloneable (Rc<RefCell>) reactive handle. UTF-8 safe (char-boundary
clamping), observable, restoration-aware.
| Group | Methods |
|---|---|
| Create | new, with_text, restored, from_value |
| Read | value, text, selection, composing, selected_text, preedit |
| Write | set_value, set_text, clear, set_selection, replace_selection, insert_text, delete_backward, delete_forward |
| Move | move_left, move_right, move_home, move_end, select_all |
| IME | set_preedit, commit_preedit, clear_preedit |
| Observe | observe, add_listener, remove_listener |
| Restore | bind_restoration, unbind_restoration |
Creating and binding
A full editing workout — copy, paste, and run:
use incular::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let controller = TextEditingController::with_text("hello");
controller.select_all();
controller.replace_selection("rust");
controller.move_home(false);
controller.insert_text("!");
controller.set_selection(TextSelection::new(0, 4));
controller.set_composing(None);
let text = controller.text();
let selected = controller.selected_text();
let app = Application::new(move |_cx| {
Container::builder()
.padding(EdgeInsets::all(24.0))
.alignment(Alignment::CENTER)
.child(
Column::builder()
.main_axis_size(MainAxisSize::Min)
.spacing(8.0)
.children(Vec::<Widget>::from([
EditableText::new(
TextEditingController::with_text(text.clone()),
).into(),
Text::new(format!(
"Selected: {selected}"
)).into(),
]))
.build(),
)
.build()
.into()
})?;
incular::run(app)?;
Ok(())
}TextEditingController::new(), restored(scope, key), from_value(value),
bind_restoration / unbind_restoration cover the remaining lifecycle.
Reading
value() (TextEditingValue), text(), selection(), composing(),
selected_text(), preedit() / preedit_selection(), caret_affinity() —
see the workout program above reading text() and selected_text().
Writing
set_value, set_text, clear, set_selection (plus
set_selection_with_affinity), set_composing, apply_delta,
replace_selection, insert_text / insert, delete_backward (backspace
alias), delete_forward (delete alias) — exercised above.
Movement
move_left / move_right / move_home / move_end (pass true to extend
the selection), plus select_all().
IME preedit
set_preedit / commit_preedit / clear_preedit manage transient
composition state (never serialized by restoration).
Observation
observe (returns a Subscription) and add_listener / remove_listener
react to value changes without rebuilding.
TextEditingValue { text, selection, composing } with new / empty /
with_selection / with_composing / replace.
TextEditingDelta { range, replacement, selection, composing } with replace
/ apply.
Related: EditableText,
TextSelection,
Restoration.