pub struct Cursor {
pub start: Pos,
pub end: Option<Pos>,
}
Expand description
A cursor is a selection of text. It has a start and end position of the selection.
Fields§
§start: Pos
The start position of the selection. The start position is the origin of the selection, not necessarily the first position.
end: Option<Pos>
The end position of the selection. If the end position is None, the cursor is a caret.
Implementations§
Source§impl Cursor
impl Cursor
Sourcepub fn from_start(pos: Pos) -> Self
pub fn from_start(pos: Pos) -> Self
Create a new cursor with the given start position.
Sourcepub fn new(start: Pos, end: Pos) -> Self
pub fn new(start: Pos, end: Pos) -> Self
Create a new cursor with the given start and end position.
Sourcepub fn move_cursor(&mut self, f: impl FnOnce(&mut Pos), shift: bool)
pub fn move_cursor(&mut self, f: impl FnOnce(&mut Pos), shift: bool)
Move the cursor position. If shift is true, the end position will be moved instead of the start position.
Sourcepub fn delete_selection<T: Text + ?Sized>(
&mut self,
text: &mut impl TextEditable<T>,
)
pub fn delete_selection<T: Text + ?Sized>( &mut self, text: &mut impl TextEditable<T>, )
Delete the currently selected text and update the cursor position.
Sourcepub fn handle_input<T: Text + ?Sized>(
&mut self,
code: &Code,
key: &Key,
modifiers: &Modifiers,
text: &mut impl TextEditable<T>,
max_text_length: usize,
)
pub fn handle_input<T: Text + ?Sized>( &mut self, code: &Code, key: &Key, modifiers: &Modifiers, text: &mut impl TextEditable<T>, max_text_length: usize, )
Handle moving the cursor with the given key.
Sourcepub fn first(&self) -> &Pos
pub fn first(&self) -> &Pos
Returns first position of the selection (this could be the start or the end depending on the position)
Sourcepub fn last(&self) -> &Pos
pub fn last(&self) -> &Pos
Returns last position of the selection (this could be the start or the end depending on the position)
Sourcepub fn selection_len(&self, text: &(impl Text + ?Sized)) -> usize
pub fn selection_len(&self, text: &(impl Text + ?Sized)) -> usize
Returns the length of the selection