pub struct EditorModel { /* private fields */ }Expand description
A multiline editing model with cursor, selection, and undo history.
The document is a Vec<String> of lines (no trailing \n stored); an
empty document is one empty line. All columns are char indices, so
multibyte text (é, 日本語) edits correctly. Runs of single-char typing
coalesce into one undo step; any other edit or movement breaks the run.
Implementations§
Source§impl EditorModel
impl EditorModel
pub fn text(&self) -> String
Sourcepub fn set_text(&mut self, text: &str)
pub fn set_text(&mut self, text: &str)
Replace the whole document, resetting cursor, selection, and history.
pub fn is_empty(&self) -> bool
pub fn line_count(&self) -> usize
pub fn cursor(&self) -> Pos
pub fn tab_size(&self) -> usize
Sourcepub fn set_tab_size(&mut self, n: usize)
pub fn set_tab_size(&mut self, n: usize)
Spaces per tab stop (min 1, default 4).
Sourcepub fn insert(&mut self, s: &str)
pub fn insert(&mut self, s: &str)
Insert s at the cursor, replacing the selection if there is one.
Embedded newlines split lines; CRLF is normalized to \n.
Sourcepub fn backspace(&mut self) -> bool
pub fn backspace(&mut self) -> bool
Delete the selection, or the char before the cursor (joining lines at a line start). Returns whether anything changed.
Sourcepub fn delete(&mut self) -> bool
pub fn delete(&mut self) -> bool
Delete the selection, or the char at the cursor (joining lines at a line end). Returns whether anything changed.
Sourcepub fn newline(&mut self)
pub fn newline(&mut self)
Split the line at the cursor, auto-indenting the new line with the current line’s leading whitespace (capped at the cursor column, so splitting inside the indent doesn’t over-indent).
Sourcepub fn tab(&mut self)
pub fn tab(&mut self)
Insert spaces up to the next tab stop (see set_tab_size).
pub fn move_left(&mut self, extend: bool)
pub fn move_right(&mut self, extend: bool)
Sourcepub fn move_up(&mut self, extend: bool)
pub fn move_up(&mut self, extend: bool)
Move up one line, keeping the goal column through shorter lines.
Sourcepub fn move_down(&mut self, extend: bool)
pub fn move_down(&mut self, extend: bool)
Move down one line, keeping the goal column through shorter lines.
pub fn home(&mut self, extend: bool)
pub fn end(&mut self, extend: bool)
pub fn doc_start(&mut self, extend: bool)
pub fn doc_end(&mut self, extend: bool)
Sourcepub fn word_left(&mut self, extend: bool)
pub fn word_left(&mut self, extend: bool)
Move left to the start of the previous word (Option+Left), crossing line boundaries.
Sourcepub fn word_right(&mut self, extend: bool)
pub fn word_right(&mut self, extend: bool)
Move right past the end of the next word (Option+Right), crossing line boundaries.
Sourcepub fn pos_for_click(&self, line: usize, col: usize) -> Pos
pub fn pos_for_click(&self, line: usize, col: usize) -> Pos
Clamp a raw (line, col) from mouse hit-testing to a valid position: line into the document, col to that line’s char length.
Sourcepub fn move_to(&mut self, line: usize, col: usize, extend: bool)
pub fn move_to(&mut self, line: usize, col: usize, extend: bool)
Move the cursor to a clicked position (clamped), extending the
selection when extend (shift-click or drag).
Sourcepub fn selection(&self) -> Option<(Pos, Pos)>
pub fn selection(&self) -> Option<(Pos, Pos)>
The selection as a normalized (start, end) pair in document order, or
None when there is no selection (or it is empty).
pub fn clear_selection(&mut self)
pub fn select_all(&mut self)
Sourcepub fn select_word(&mut self)
pub fn select_word(&mut self)
Select the word around the cursor (double-click). On a non-word char, selects just that char.
Sourcepub fn select_line(&mut self)
pub fn select_line(&mut self)
Select the cursor’s whole line (triple-click).
Sourcepub fn selected_text(&self) -> Option<String>
pub fn selected_text(&self) -> Option<String>
The selected text, None when nothing is selected.
Sourcepub fn delete_selection(&mut self) -> bool
pub fn delete_selection(&mut self) -> bool
Delete the selected text. Returns whether anything changed.
Sourcepub fn cut(&mut self) -> Option<String>
pub fn cut(&mut self) -> Option<String>
Remove and return the selected text; None when nothing is selected.
pub fn can_undo(&self) -> bool
pub fn can_redo(&self) -> bool
Trait Implementations§
Source§impl Clone for EditorModel
impl Clone for EditorModel
Source§fn clone(&self) -> EditorModel
fn clone(&self) -> EditorModel
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EditorModel
impl Debug for EditorModel
Auto Trait Implementations§
impl Freeze for EditorModel
impl RefUnwindSafe for EditorModel
impl Send for EditorModel
impl Sync for EditorModel
impl Unpin for EditorModel
impl UnsafeUnpin for EditorModel
impl UnwindSafe for EditorModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().