nativeview_engine/editing/
focus.rs1use nativeview_abi::NodeId;
4
5
6#[derive(Debug, Clone, Default, PartialEq, Eq)]
8pub struct TextFocusState {
9 pub focused_node: Option<NodeId>,
10 pub caret_byte_index: usize,
11 pub selection_anchor: usize,
12 pub ime_preedit: Option<String>,
13 pub ime_preedit_cursor: Option<(usize, usize)>,
14 pub uncontrolled_value: Option<String>,
15}
16
17impl TextFocusState {
18 #[inline]
19 pub fn selection_range(&self) -> Option<(usize, usize)> {
20 if self.selection_anchor != self.caret_byte_index {
21 Some((
22 self.selection_anchor.min(self.caret_byte_index),
23 self.selection_anchor.max(self.caret_byte_index),
24 ))
25 } else {
26 None
27 }
28 }
29}
30