Skip to main content

FocusedTextFieldHandler

Trait FocusedTextFieldHandler 

Source
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§

Source

fn handle_key(&self, event: &KeyEvent) -> bool

Handle a key event. Returns true if consumed.

Source

fn insert_text(&self, text: &str)

Insert pasted text.

Source

fn delete_surrounding(&self, before_bytes: usize, after_bytes: usize)

Delete text surrounding the cursor or selection.

Source

fn copy_selection(&self) -> Option<String>

Copy current selection. Returns None if nothing selected.

Source

fn cut_selection(&self) -> Option<String>

Cut current selection (copy + delete). Returns None if nothing selected.

Source

fn set_composition(&self, text: &str, cursor: Option<(usize, usize)>)

Set IME composition (preedit) state.

  • text: The composition text being typed (empty string to clear, which deletes the preedit text)
  • cursor: Optional cursor position within composition (start, end)

Provided Methods§

Source

fn select_all(&self)

Selects all the field’s text (contextual-menu “Select all”).

Source

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.

Source

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.

Source

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.

Source

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".

Implementors§