pub struct Editor<'a> { /* private fields */ }Expand description
Short-lived access to a model for one editor. Creating it syncs the cursors.
Implementations§
Source§impl Editor<'_>
impl Editor<'_>
Sourcepub fn tab(&mut self)
pub fn tab(&mut self)
Tab: indents the selected lines when a selection spans lines, otherwise inserts indentation at each cursor.
Sourcepub fn indent_lines(&mut self)
pub fn indent_lines(&mut self)
Adds one indentation unit at the start of every selected non-blank line.
Sourcepub fn outdent_lines(&mut self)
pub fn outdent_lines(&mut self)
Shift+Tab: removes up to one indentation unit from the start of every selected line.
Sourcepub fn move_lines(&mut self, up: bool)
pub fn move_lines(&mut self, up: bool)
Alt+Up / Alt+Down: moves the selected lines past the line above or below.
Sourcepub fn copy_lines(&mut self, up: bool)
pub fn copy_lines(&mut self, up: bool)
Shift+Alt+Up / Shift+Alt+Down: duplicates the selected lines above or below; the selections end up on the copy.
Sourcepub fn delete_lines(&mut self)
pub fn delete_lines(&mut self)
Ctrl+Shift+K: deletes the selected lines; cursors keep their column on the next line.
Sourcepub fn insert_line(&mut self, below: bool)
pub fn insert_line(&mut self, below: bool)
Ctrl+Enter (below) / Ctrl+Shift+Enter (above): opens a new line with the current line’s indentation and moves the cursor onto it.
Sourcepub fn toggle_line_comment(&mut self)
pub fn toggle_line_comment(&mut self)
Ctrl+/: comments out the selected lines with the language’s line comment token, or uncomments them when every non-blank one is already commented. Falls back to a block comment for languages without line comments.
Sourcepub fn toggle_block_comment(&mut self)
pub fn toggle_block_comment(&mut self)
Shift+Alt+A: wraps each selection in the language’s block comment tokens, keeping the selection on the wrapped text, or removes the tokens when they sit just inside or just outside the selection.
Sourcepub fn type_char(&mut self, c: char)
pub fn type_char(&mut self, c: char)
Types one char with bracket handling: an opening char of an auto-closing pair inserts the pair (or wraps a selection in it), a closing char steps over the same char after the cursor. Other chars are typed as usual.
Sourcepub fn type_char_in(&mut self, c: char, in_literal: bool)
pub fn type_char_in(&mut self, c: char, in_literal: bool)
Like Editor::type_char; inside a string or comment (in_literal) no pair is
opened, but a closing char still steps over the same char after the cursor.
Sourcepub fn delete_backward_pair(&mut self)
pub fn delete_backward_pair(&mut self)
Backspace that also removes the closing half of an empty auto-closing pair.
Sourcepub fn add_next_occurrence(&mut self)
pub fn add_next_occurrence(&mut self)
Ctrl+D: selects the word at the cursor, or adds the next occurrence of the primary selection’s text as a new selection (wrapping at the end of the document).
Sourcepub fn select_all_occurrences(&mut self)
pub fn select_all_occurrences(&mut self)
Ctrl+Shift+L: selects every occurrence of the primary selection’s text (or of the word at the cursor).
Sourcepub fn expand_selection(&mut self, ranges: &[Range<usize>]) -> bool
pub fn expand_selection(&mut self, ranges: &[Range<usize>]) -> bool
Expands the primary selection to the smallest of ranges (syntax node ranges from the
language module, innermost first) that contains it and is larger. The previous
selections are kept for Editor::shrink_selection.
Sourcepub fn shrink_selection(&mut self) -> bool
pub fn shrink_selection(&mut self) -> bool
Goes back to the selections before the last Editor::expand_selection.
Sourcepub fn transform_case(&mut self, upper: bool)
pub fn transform_case(&mut self, upper: bool)
Converts the selected text (or the word at each cursor) to upper or lower case.
Sourcepub fn trim_trailing_whitespace(&mut self)
pub fn trim_trailing_whitespace(&mut self)
Removes spaces and tabs at the end of every line.
Source§impl Editor<'_>
impl Editor<'_>
Sourcepub fn replace_all(
&mut self,
searcher: &Searcher,
replacement: &str,
regex_mode: bool,
) -> usize
pub fn replace_all( &mut self, searcher: &Searcher, replacement: &str, regex_mode: bool, ) -> usize
Replaces every match of searcher with replacement (capture groups in regex mode)
as one undo step. Returns the number of replacements.
Sourcepub fn select_matches(&mut self, searcher: &Searcher) -> usize
pub fn select_matches(&mut self, searcher: &Searcher) -> usize
Selects every match of searcher (Alt+Enter in the find widget).
Source§impl<'a> Editor<'a>
impl<'a> Editor<'a>
pub fn new(model: &'a mut TextModel, cursors: &'a mut Cursors) -> Self
pub fn selections(&self) -> &Selections
pub fn set_selections(&mut self, selections: Selections)
Sourcepub fn cursor_undo(&mut self) -> bool
pub fn cursor_undo(&mut self) -> bool
Ctrl+U: goes back to the selections before the last cursor change. Text edits clear the history, since older positions would point into changed text.
Sourcepub fn compose(&mut self, before: usize, text: &str)
pub fn compose(&mut self, before: usize, text: &str)
Replaces the before chars ahead of each caret (or a selection, when there is one)
with text: one step of an IME composition, which replaces what the previous step
inserted. Steps undo together with the typing around them.
Sourcepub fn paste_each(&mut self, pieces: &[String])
pub fn paste_each(&mut self, pieces: &[String])
Pastes one piece per cursor, as copied from the same number of selections.
Sourcepub fn selection_texts(&self) -> Vec<String>
pub fn selection_texts(&self) -> Vec<String>
The text of each non-empty selection, in order; for clipboard metadata.
Sourcepub fn move_heads(
&mut self,
extend: bool,
f: impl FnMut(&Rope, &Selection) -> (usize, Option<usize>),
)
pub fn move_heads( &mut self, extend: bool, f: impl FnMut(&Rope, &Selection) -> (usize, Option<usize>), )
Moves every caret to the head f returns, with its goal column; frontends use it for
moves that depend on layout, such as stepping over folded lines.
Sourcepub fn newline(&mut self)
pub fn newline(&mut self)
Inserts a line break and copies the current line’s indentation up to the caret.
Sourcepub fn delete_backward(&mut self)
pub fn delete_backward(&mut self)
Backspace: deletes the selection, or the char before each cursor.
Sourcepub fn delete_forward(&mut self)
pub fn delete_forward(&mut self)
Delete: deletes the selection, or the char after each cursor.
Sourcepub fn delete_word_backward(&mut self)
pub fn delete_word_backward(&mut self)
Ctrl+Backspace: deletes the selection, or back to the previous word start.
Sourcepub fn delete_word_forward(&mut self)
pub fn delete_word_forward(&mut self)
Ctrl+Delete: deletes the selection, or forward to the next word end.
Sourcepub fn apply_edits(&mut self, edits: Vec<Edit>)
pub fn apply_edits(&mut self, edits: Vec<Edit>)
Applies edits that did not come from typing, such as LSP text edits or formatting. Selections follow the text around them.
Sourcepub fn copy(&self) -> String
pub fn copy(&self) -> String
Text for the clipboard. With only empty cursors, copies their whole lines.
Sourcepub fn paste(&mut self, text: &str)
pub fn paste(&mut self, text: &str)
Pastes text. When it has exactly one line per cursor, each cursor gets its own line.
pub fn move_left(&mut self, extend: bool)
pub fn move_right(&mut self, extend: bool)
pub fn move_word_left(&mut self, extend: bool)
pub fn move_word_right(&mut self, extend: bool)
pub fn move_up(&mut self, extend: bool)
pub fn move_down(&mut self, extend: bool)
Sourcepub fn move_vertical(&mut self, lines: isize, extend: bool)
pub fn move_vertical(&mut self, lines: isize, extend: bool)
Moves every caret lines lines up (negative) or down, keeping the goal column.
Sourcepub fn move_line_start(&mut self, extend: bool)
pub fn move_line_start(&mut self, extend: bool)
Home: toggles between the first non-whitespace char and column 0.
pub fn move_line_end(&mut self, extend: bool)
pub fn move_document_start(&mut self, extend: bool)
pub fn move_document_end(&mut self, extend: bool)
pub fn select_all(&mut self)
Sourcepub fn add_cursor_vertical(&mut self, below: bool)
pub fn add_cursor_vertical(&mut self, below: bool)
Adds a cursor one line below the last cursor (or above the first one) and makes it primary.
Sourcepub fn undo(&mut self) -> bool
pub fn undo(&mut self) -> bool
Undoes the last step in the model, whichever editor made it. The editor that made it gets its selections back; any other editor’s cursors follow the text.
pub fn redo(&mut self) -> bool
Source§impl Editor<'_>
impl Editor<'_>
Sourcepub fn insert_snippet(&mut self, snippet: &Snippet)
pub fn insert_snippet(&mut self, snippet: &Snippet)
Inserts snippet at every selection, replacing selected text, indents its lines like
the line it lands on, and selects its first tab stop.
Sourcepub fn next_snippet_stop(&mut self) -> bool
pub fn next_snippet_stop(&mut self) -> bool
Moves to the next tab stop; at $0 the session ends. False without a session.
Sourcepub fn prev_snippet_stop(&mut self) -> bool
pub fn prev_snippet_stop(&mut self) -> bool
Moves to the previous tab stop. False without a session.
Sourcepub fn end_snippet(&mut self)
pub fn end_snippet(&mut self)
Ends the active snippet session, if any.
Sourcepub fn check_snippet(&mut self)
pub fn check_snippet(&mut self)
Ends the session when the primary caret has left every tab stop.
Sourcepub fn snippet(&self) -> Option<&SnippetSession>
pub fn snippet(&self) -> Option<&SnippetSession>
The active snippet session.