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 editing: UAX #29 grapheme/word/paragraph stepping, BiDi visual line
//! layout (`VisualGraphemeCluster`, `ShapedLineLayout`), and `TextFocusState` (caret, selection,
//! IME composition).

pub mod bidi;
pub mod focus;
pub mod grapheme;

pub use bidi::{ShapedLineLayout, VisualGraphemeCluster};
pub use focus::TextFocusState;
pub use grapheme::{
    clamp_grapheme_boundary, grapheme_boundaries, grapheme_count, is_grapheme_boundary,
    next_grapheme_boundary, normalize_line_endings, paragraph_bounds_at, prev_grapheme_boundary,
    word_bounds_at,
};

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn grapheme_zwj_flag_combining_and_crlf_boundaries() {
        let zwj = "a๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆb";
        assert_eq!(grapheme_count(zwj), 3);
        assert_eq!(next_grapheme_boundary(zwj, 0), 1);
        assert_eq!(next_grapheme_boundary(zwj, 1), zwj.len() - 1);
        assert_eq!(prev_grapheme_boundary(zwj, zwj.len() - 1), 1);
        assert_eq!(clamp_grapheme_boundary(zwj, 4), 1);

        let flag = "๐Ÿ‡ฉ๐Ÿ‡ชx";
        assert_eq!(grapheme_count(flag), 2);
        assert_eq!(next_grapheme_boundary(flag, 0), flag.len() - 1);

        assert_eq!(normalize_line_endings("a\r\nb\rc"), "a\nb\nc");
    }

    #[test]
    fn focus_state_selection_range_and_reset() {
        let mut st = TextFocusState::default();
        assert_eq!(st.selection_range(), None);
        st.selection_anchor = 5;
        st.caret_byte_index = 2;
        assert_eq!(st.selection_range(), Some((2, 5)));
        assert!(st.selection_range().is_some());
    }
}