Skip to main content

Editor

Struct Editor 

Source
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<'_>

Source

pub fn tab(&mut self)

Tab: indents the selected lines when a selection spans lines, otherwise inserts indentation at each cursor.

Source

pub fn indent_lines(&mut self)

Adds one indentation unit at the start of every selected non-blank line.

Source

pub fn outdent_lines(&mut self)

Shift+Tab: removes up to one indentation unit from the start of every selected line.

Source

pub fn move_lines(&mut self, up: bool)

Alt+Up / Alt+Down: moves the selected lines past the line above or below.

Source

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.

Source

pub fn delete_lines(&mut self)

Ctrl+Shift+K: deletes the selected lines; cursors keep their column on the next line.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn delete_backward_pair(&mut self)

Backspace that also removes the closing half of an empty auto-closing pair.

Source

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).

Source

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).

Source

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.

Source

pub fn shrink_selection(&mut self) -> bool

Goes back to the selections before the last Editor::expand_selection.

Source

pub fn transform_case(&mut self, upper: bool)

Converts the selected text (or the word at each cursor) to upper or lower case.

Source

pub fn trim_trailing_whitespace(&mut self)

Removes spaces and tabs at the end of every line.

Source§

impl Editor<'_>

Source

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.

Source

pub fn select_matches(&mut self, searcher: &Searcher) -> usize

Selects every match of searcher (Alt+Enter in the find widget).

Source§

impl Editor<'_>

Source

pub fn run(&mut self, command: &str) -> bool

Runs a command by its id (VS Code’s names). Returns false for ids the core does not handle; frontends run those themselves (page movement needs the view, clipboard commands need the platform clipboard).

Source§

impl<'a> Editor<'a>

Source

pub fn new(model: &'a mut TextModel, cursors: &'a mut Cursors) -> Self

Source

pub fn model(&self) -> &TextModel

The model being edited.

Source

pub fn selections(&self) -> &Selections

Source

pub fn set_selections(&mut self, selections: Selections)

Source

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.

Source

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.

Source

pub fn paste_each(&mut self, pieces: &[String])

Pastes one piece per cursor, as copied from the same number of selections.

Source

pub fn selection_texts(&self) -> Vec<String>

The text of each non-empty selection, in order; for clipboard metadata.

Source

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.

Source

pub fn insert(&mut self, text: &str)

Types text at every selection, replacing selected text.

Source

pub fn newline(&mut self)

Inserts a line break and copies the current line’s indentation up to the caret.

Source

pub fn indent(&mut self)

Inserts indentation up to the next tab stop at every cursor.

Source

pub fn delete_backward(&mut self)

Backspace: deletes the selection, or the char before each cursor.

Source

pub fn delete_forward(&mut self)

Delete: deletes the selection, or the char after each cursor.

Source

pub fn delete_word_backward(&mut self)

Ctrl+Backspace: deletes the selection, or back to the previous word start.

Source

pub fn delete_word_forward(&mut self)

Ctrl+Delete: deletes the selection, or forward to the next word end.

Source

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.

Source

pub fn copy(&self) -> String

Text for the clipboard. With only empty cursors, copies their whole lines.

Source

pub fn cut(&mut self) -> String

Copies, then deletes what was copied.

Source

pub fn paste(&mut self, text: &str)

Pastes text. When it has exactly one line per cursor, each cursor gets its own line.

Source

pub fn move_left(&mut self, extend: bool)

Source

pub fn move_right(&mut self, extend: bool)

Source

pub fn move_word_left(&mut self, extend: bool)

Source

pub fn move_word_right(&mut self, extend: bool)

Source

pub fn move_up(&mut self, extend: bool)

Source

pub fn move_down(&mut self, extend: bool)

Source

pub fn move_vertical(&mut self, lines: isize, extend: bool)

Moves every caret lines lines up (negative) or down, keeping the goal column.

Source

pub fn move_line_start(&mut self, extend: bool)

Home: toggles between the first non-whitespace char and column 0.

Source

pub fn move_line_end(&mut self, extend: bool)

Source

pub fn move_document_start(&mut self, extend: bool)

Source

pub fn move_document_end(&mut self, extend: bool)

Source

pub fn select_all(&mut self)

Source

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.

Source

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.

Source

pub fn redo(&mut self) -> bool

Source§

impl Editor<'_>

Source

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.

Source

pub fn next_snippet_stop(&mut self) -> bool

Moves to the next tab stop; at $0 the session ends. False without a session.

Source

pub fn prev_snippet_stop(&mut self) -> bool

Moves to the previous tab stop. False without a session.

Source

pub fn end_snippet(&mut self)

Ends the active snippet session, if any.

Source

pub fn check_snippet(&mut self)

Ends the session when the primary caret has left every tab stop.

Source

pub fn snippet(&self) -> Option<&SnippetSession>

The active snippet session.

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for Editor<'a>

§

impl<'a> Forget for Editor<'a>

§

impl<'a> Freeze for Editor<'a>

§

impl<'a> Move for Editor<'a>

§

impl<'a> RefUnwindSafe for Editor<'a>

§

impl<'a> Send for Editor<'a>

§

impl<'a> Sync for Editor<'a>

§

impl<'a> Unpin for Editor<'a>

§

impl<'a> UnsafeUnpin for Editor<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.