Skip to main content

fret_runtime/
platform_text_input.rs

1use fret_core::{Point, Rect};
2
3/// UTF-16 code unit range used by platform text input and accessibility bridges.
4///
5/// Coordinate model: UTF-16 code units over a widget's **composed view** (base buffer text with
6/// active IME preedit spliced at the caret).
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub struct Utf16Range {
9    pub start: u32,
10    pub end: u32,
11}
12
13impl Utf16Range {
14    pub fn new(start: u32, end: u32) -> Self {
15        Self { start, end }
16    }
17
18    pub fn normalized(self) -> Self {
19        Self {
20            start: self.start.min(self.end),
21            end: self.start.max(self.end),
22        }
23    }
24
25    pub fn is_empty(self) -> bool {
26        self.start == self.end
27    }
28}
29
30/// Minimal platform text input handler surface (Zed/GPUI-inspired).
31///
32/// v1: indices are UTF-16 code units over the composed view.
33#[derive(Debug, Clone, PartialEq)]
34pub enum PlatformTextInputQuery {
35    SelectedTextRange,
36    MarkedTextRange,
37    TextForRange { range: Utf16Range },
38    BoundsForRange { range: Utf16Range },
39    CharacterIndexForPoint { point: Point },
40}
41
42#[derive(Debug, Clone, PartialEq)]
43pub enum PlatformTextInputQueryResult {
44    Range(Option<Utf16Range>),
45    Text(Option<String>),
46    Bounds(Option<Rect>),
47    Index(Option<u32>),
48}