pub struct ImeSurroundingText { /* private fields */ }Expand description
Defines the text surrounding the caret
Implementations§
Source§impl ImeSurroundingText
impl ImeSurroundingText
Sourcepub const MAX_TEXT_BYTES: usize = 4000
pub const MAX_TEXT_BYTES: usize = 4000
The maximum size of the text excerpt.
Sourcepub fn new(
text: String,
cursor: usize,
anchor: usize,
) -> Result<Self, ImeSurroundingTextError>
pub fn new( text: String, cursor: usize, anchor: usize, ) -> Result<Self, ImeSurroundingTextError>
Defines the text surrounding the cursor and the selection within it.
text: An excerpt of the text present in the text input field, excluding preedit.
It must be limited to 4000 bytes due to backend constraints.
cursor: The position of the caret, in bytes from the beginning of the string.
`anchor: The position of the other end of selection, in bytes.
With no selection, it should be the same as the cursor.
This may fail if the byte indices don’t fall on code point boundaries, or if the text is too long.
§Examples:
A text field containing foo|bar where | denotes the caret would correspond to a value
obtained by:
let s = ImeSurroundingText::new("foobar".into(), 3, 3).unwrap();Because preedit is excluded from the text string, a text field containing foo[baz|]bar
where | denotes the caret and [baz|] is the preedit would be created in exactly the same
way.
Sourcepub fn into_text(self) -> String
pub fn into_text(self) -> String
Consumes the object, releasing the text string only. Use this call in the backend to avoid an extra clone when submitting the surrounding text.