pub trait FocusedTextFieldHandler {
// Required methods
fn handle_key(&self, event: &KeyEvent) -> bool;
fn insert_text(&self, text: &str);
fn delete_surrounding(&self, before_bytes: usize, after_bytes: usize);
fn copy_selection(&self) -> Option<String>;
fn cut_selection(&self) -> Option<String>;
fn set_composition(&self, text: &str, cursor: Option<(usize, usize)>);
// Provided methods
fn select_all(&self) { ... }
fn finish_composition(&self) { ... }
fn set_composing_region(&self, start_bytes: usize, end_bytes: usize) { ... }
fn set_selection(&self, start_bytes: usize, end_bytes: usize) { ... }
fn editor_state(&self) -> Option<ImeEditorState> { ... }
}Expand description
Handler trait for focused text field operations. Stored in focus module for O(1) key/clipboard dispatch.
Required Methods§
Sourcefn handle_key(&self, event: &KeyEvent) -> bool
fn handle_key(&self, event: &KeyEvent) -> bool
Handle a key event. Returns true if consumed.
Sourcefn insert_text(&self, text: &str)
fn insert_text(&self, text: &str)
Insert pasted text.
Sourcefn delete_surrounding(&self, before_bytes: usize, after_bytes: usize)
fn delete_surrounding(&self, before_bytes: usize, after_bytes: usize)
Delete text surrounding the cursor or selection.
Sourcefn copy_selection(&self) -> Option<String>
fn copy_selection(&self) -> Option<String>
Copy current selection. Returns None if nothing selected.
Sourcefn cut_selection(&self) -> Option<String>
fn cut_selection(&self) -> Option<String>
Cut current selection (copy + delete). Returns None if nothing selected.
Provided Methods§
Sourcefn select_all(&self)
fn select_all(&self)
Selects all the field’s text (contextual-menu “Select all”).
Sourcefn finish_composition(&self)
fn finish_composition(&self)
Finish the active composition, keeping the composed text as regular
committed text (Android finishComposingText semantics). No-op when
no composition is active.
Sourcefn set_composing_region(&self, start_bytes: usize, end_bytes: usize)
fn set_composing_region(&self, start_bytes: usize, end_bytes: usize)
Mark existing text as the composing region without changing it
(Android setComposingRegion semantics, used by autocorrect to
re-compose an already committed word). Offsets are UTF-8 bytes;
implementations clamp them to valid character boundaries.
Sourcefn set_selection(&self, start_bytes: usize, end_bytes: usize)
fn set_selection(&self, start_bytes: usize, end_bytes: usize)
Move the selection/caret to [start_bytes, end_bytes) without editing
text (Android InputConnection.setSelection semantics). Used by
Gboard’s spacebar-swipe cursor control, which scrubs the caret by
repeatedly setting the selection. Offsets are UTF-8 bytes; implementations
clamp them to valid character boundaries.
Sourcefn editor_state(&self) -> Option<ImeEditorState>
fn editor_state(&self) -> Option<ImeEditorState>
Snapshot of the current editable state for platform IMEs
(InputConnection text queries, session seeding). None when the
handler cannot expose its state.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".