nativeview-engine 0.1.0-rc.1

Framework-agnostic scene engine traits, hot-reload cdylib loader, and Frame-0 snapshot codecs.
Documentation
//! Platform-agnostic text focus, caret, selection, and IME composition state.

use nativeview_abi::NodeId;


/// Active focus, caret, range selection, and IME composition state tracked by retained backends.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct TextFocusState {
    pub focused_node: Option<NodeId>,
    pub caret_byte_index: usize,
    pub selection_anchor: usize,
    pub ime_preedit: Option<String>,
    pub ime_preedit_cursor: Option<(usize, usize)>,
    pub uncontrolled_value: Option<String>,
}

impl TextFocusState {
    #[inline]
    pub fn selection_range(&self) -> Option<(usize, usize)> {
        if self.selection_anchor != self.caret_byte_index {
            Some((
                self.selection_anchor.min(self.caret_byte_index),
                self.selection_anchor.max(self.caret_byte_index),
            ))
        } else {
            None
        }
    }
}