Skip to main content

CodeEditor

Struct CodeEditor 

Source
pub struct CodeEditor { /* private fields */ }
Expand description

Represents the text editor, which holds the code buffer, cursor, selection, theme, scroll offsets, highlight cache, clipboard, and user mark intervals.

Implementations§

Source§

impl Editor

Source

pub fn new( lang: &str, text: &str, theme: Vec<(&str, &str)>, ) -> Result<Editor, Error>

Create an editor for the given language, text, and syntax theme.

§Errors

Returns an error when neither the requested language grammar nor the text fallback grammar can be loaded.

Source

pub fn new_with_highlights( lang: &str, text: &str, theme: Vec<(&str, &str)>, custom_highlights: Option<HashMap<String, String>>, ) -> Result<Editor, Error>

Create an editor with optional custom highlight overrides.

§Errors

Returns an error when neither the requested language grammar nor the text fallback grammar can be loaded.

Source

pub fn set_text_style(&mut self, style: Style)

Set the style for ordinary text (the foreground of unhighlighted code).

Source

pub fn set_line_number_style(&mut self, style: Style)

Set the style for the line-number gutter.

Source

pub fn set_relative_line_numbers(&mut self, on: bool)

Enable or disable relative (hybrid) line numbering.

Source

pub fn set_cursor_style(&mut self, style: Option<Style>)

Set the block-cursor style. Pass Some(style) to draw a visible cursor cell (its bg is the cursor color), or None to draw no cursor.

Source

pub fn set_syntax_theme(&mut self, theme: &[(&str, &str)])

Replace the syntax-highlight theme (token name -> #rrggbb) and drop the cached highlights so the new colors take effect on the next render.

Source

pub fn set_selection_style(&mut self, style: Style)

Set the style applied to the active selection.

Source

pub fn focus(&mut self, area: &Rect)

Scroll the viewport so the cursor is visible within area.

Source

pub fn handle_mouse_down(&mut self, cursor: usize)

Handles a mouse button press at the given cursor position, updating selection and click state.

Source

pub fn handle_mouse_drag(&mut self, cursor: usize)

Handles a mouse drag event at the given cursor position, extending the selection.

Source

pub fn cursor_from_mouse( &self, mouse_x: u16, mouse_y: u16, area: &Rect, ) -> Option<usize>

Converts mouse coordinates to a cursor position within the editor area, returning None if outside.

Source

pub fn clear_selection(&mut self)

Clears any active selection.

Source

pub fn extend_selection(&mut self, new_cursor: usize)

Extends or starts a selection from the current cursor to new_cursor.

Source

pub fn selection_anchor(&self) -> usize

Returns the selection anchor position, or the cursor if no selection exists.

Source

pub fn apply<A>(&mut self, action: A)
where A: Action,

Apply an editing action to the buffer.

Source

pub fn set_content(&mut self, content: &str)

Replace the entire buffer contents with content as a single undo step.

Source

pub fn apply_batch(&mut self, batch: &EditBatch)

Apply a batch of edits as a single undo step.

Source

pub fn set_cursor(&mut self, cursor: usize)

Move the cursor to the given char offset, clamped to the buffer. Clears the vertical-movement goal column; line up/down re-establish it afterward.

Source

pub fn set_selection_range(&mut self, anchor: usize, cursor: usize)

Select the range [anchor, cursor), putting the caret at cursor. An empty range (anchor == cursor) just clears the selection.

Source

pub fn fit_cursor(&mut self)

Clamp the cursor so it stays within the buffer and its current line.

Source

pub fn scroll_up(&mut self)

Scroll the viewport up one line.

Source

pub fn scroll_down(&mut self, area_height: usize)

Scroll the viewport down one line, bounded by the last line.

Source

pub fn get_content(&self) -> String

Return the entire buffer contents as an owned string.

Source

pub fn get_content_slice(&self, start: usize, end: usize) -> String

Return the text of the char range [start, end) as an owned string.

Source

pub fn get_cursor(&self) -> usize

Return the cursor’s char offset.

Source

pub fn cursor_line(&self) -> usize

The 0-based line (row) the cursor is on.

Source

pub fn comment_prefix(&self) -> String

The line-comment prefix for this buffer’s language (e.g. // or #).

Source

pub fn set_cursor_line(&mut self, line: usize)

Move the cursor to the start of 0-based line (clamped to the buffer) and clear any selection.

Source

pub fn set_clipboard(&mut self, text: &str) -> Result<(), Error>

Set the clipboard text, falling back to an in-memory clipboard when the system clipboard is unavailable.

§Errors

Currently always returns Ok; the system-clipboard failure path falls back to the in-memory clipboard.

Source

pub fn get_clipboard(&self) -> Result<String, Error>

Return the clipboard text, preferring the system clipboard and falling back to the in-memory clipboard.

§Errors

Returns an error when neither the system nor in-memory clipboard has text.

Source

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

Insert text at the cursor as one edit — one undo step — replacing the selection if there is one and re-indenting the pasted block to the cursor’s level (see Code::smart_paste).

Shared by the Paste action, which pastes the clipboard, and the host’s bracketed-paste handler, which pastes the text the terminal hands over. Going through one path is what keeps a terminal paste undoable in a single step: replayed as individual key events it would leave one undo entry per character.

Source

pub fn set_marks(&mut self, marks: Vec<(usize, usize, &str)>)

Set the highlight marks as (start char, end char, hex color) ranges.

Source

pub fn marks(&self) -> Option<&Vec<(usize, usize, Color)>>

The current highlight marks (search matches and similar), as (start char, end char, color) ranges, if any.

Source

pub fn remove_marks(&mut self)

Clear all highlight marks.

Source

pub fn set_fold_ranges(&mut self, ranges: Vec<(usize, usize)>)

Record the foldable line ranges reported by the language server. Drops any active fold whose range is no longer offered.

Source

pub fn toggle_fold(&mut self, line: usize) -> bool

Toggle the fold whose start is line: unfold it if folded, else fold it if a foldable range starts there. Returns true if anything changed.

Source

pub fn toggle_manual_fold(&mut self, start: usize, end: usize) -> bool

Toggle a fold over the explicit inclusive (start, end) line range, without a language server having reported it — used for Org drawer folding, where the range is computed on the fly. Folds the range if it is open, unfolds it if already folded, keeping the caret out of the hidden region. Returns true if the fold state changed (always, unless the range is empty). The folded start line renders the ▸ marker and a trailing ..., matching code folding.

Source

pub fn is_line_hidden(&self, line: usize) -> bool

Whether line is hidden inside a currently-folded range (start < line <= end).

Source

pub fn has_folds(&self) -> bool

Whether any fold is currently active.

Source

pub fn fold_all(&mut self)

Fold every foldable range.

Source

pub fn unfold_all(&mut self)

Unfold every active fold.

Source

pub fn set_inlay_hints(&mut self, hints: Vec<(usize, usize, String)>)

Set the inline hints to display: (line, char column within line, label).

Source

pub fn set_semantic_tokens(&mut self, tokens: Vec<(usize, usize, String)>)

Replace the LSP semantic-token overlay (T123a): (start char, end char, theme capture name) spans, merged into Tree-sitter’s own highlighting at render time (draw_syntax_layer).

Source

pub fn has_inlay_hints(&self) -> bool

Whether any inline hints are set.

Source

pub fn fold_marker(&self, line: usize) -> Option<bool>

The fold marker for line: Some(true) if a folded range starts here, Some(false) if a foldable (but open) range starts here, else None.

Source

pub fn set_spell_marks(&mut self, marks: Vec<(usize, usize)>)

Set the spell-check underline marks (char ranges of misspelled words).

Source

pub fn clear_spell_marks(&mut self)

Clear all spell-check underline marks.

Source

pub fn spell_marks(&self) -> Option<&Vec<(usize, usize)>>

The current spell-check underline marks (char ranges), if any.

Source

pub fn set_word_marks(&mut self, marks: Vec<(usize, usize)>)

Set the passive word-occurrence marks (char ranges); empty clears them.

Source

pub fn word_marks(&self) -> Option<&Vec<(usize, usize)>>

The current word-occurrence marks (char ranges), if any.

Source

pub fn set_diagnostic_marks(&mut self, marks: Vec<(usize, usize, Color)>)

Set the LSP diagnostic underline marks: (start char, end char, color).

Source

pub fn clear_diagnostic_marks(&mut self)

Clear all LSP diagnostic underline marks.

Source

pub fn diagnostic_marks(&self) -> Option<&Vec<(usize, usize, Color)>>

The current LSP diagnostic underline marks, if any.

Source

pub fn set_gutter_marks(&mut self, marks: Vec<(usize, &str)>)

Set the git diff gutter marks: (line index, hex color) per changed line.

Source

pub fn clear_gutter_marks(&mut self)

Clear all git diff gutter marks.

Source

pub fn gutter_marks(&self) -> Option<&Vec<(usize, Color)>>

The current git diff gutter marks (line index, color), if any.

Source

pub fn comment_string_ranges(&self) -> Vec<(usize, usize)>

Char ranges of comment and string tokens in the buffer, for the host’s spell checker to scan. Empty when the language has no Tree-sitter query.

Source

pub fn char_text(&self, start: usize, end: usize) -> String

The text of the char range [start, end) as an owned string.

Source

pub fn word_at(&self, pos: usize) -> Option<(usize, usize, String)>

The word (and its char range) at pos, using the buffer’s word boundaries; None when pos is not inside a word.

Source

pub fn has_marks(&self) -> bool

Whether any highlight marks are set.

Source

pub fn get_marks(&self) -> Option<&Vec<(usize, usize, Color)>>

Return the highlight marks as (start, end, color) ranges, if any.

Source

pub fn get_selection_text(&mut self) -> Option<String>

Return the text of the current selection, or None when empty.

Source

pub fn get_selection(&mut self) -> Option<Selection>

Return the current selection, if any.

Source

pub fn set_selection(&mut self, selection: Option<Selection>)

Set (or clear) the current selection.

Source

pub fn set_offset_y(&mut self, offset_y: usize)

Set the vertical scroll offset (first visible line).

Source

pub fn set_offset_x(&mut self, offset_x: usize)

Set the horizontal scroll offset (first visible column).

Source

pub fn get_offset_y(&self) -> usize

Return the vertical scroll offset (first visible line).

Source

pub fn get_offset_x(&self) -> usize

Return the horizontal scroll offset (first visible column).

Source

pub fn soft_wrap_enabled(&self) -> bool

Whether soft wrap is on (no horizontal scrolling when it is).

Source

pub fn gutter_width(&self) -> usize

Width (columns) of the line-number gutter, so the host can compute the visible text width for a horizontal scrollbar.

Source

pub fn max_line_width(&self) -> usize

The longest line’s width in characters (used to size a horizontal scrollbar). A tab counts as one character.

Source

pub fn code_mut(&mut self) -> &mut Code

Return a mutable reference to the underlying code buffer.

Source

pub fn code_ref(&self) -> &Code

Return a shared reference to the underlying code buffer.

Source

pub fn top_line(&self) -> usize

The 0-based index of the first visible line (the vertical scroll offset).

Source

pub fn poll_parse(&mut self) -> bool

Install any completed background reparse (large buffers). Returns true when the syntax tree was updated, so the host can redraw.

Source

pub fn parse_pending(&self) -> bool

Whether a background reparse is in flight for this buffer.

Source

pub fn switch_undo_branch(&mut self) -> bool

Cycle which undo-tree branch the next redo will follow. Returns true when the current state has more than one branch.

Source

pub fn revision(&self) -> u64

A counter that increases on every content edit, for cheap change detection (e.g. deciding when to push a didChange to a language server).

Source

pub fn language(&self) -> &str

The buffer’s language identifier (e.g. "rust", "text").

Source

pub fn line_ending(&self) -> &'static str

The buffer’s line ending: "LF" or "CRLF".

Source

pub fn selection_span(&self) -> Option<(usize, usize)>

The current selection as a sorted (start, end) char range, or None when there is no (non-empty) selection.

Source

pub fn set_change_callback( &mut self, callback: Box<dyn Fn(Vec<(usize, usize, usize, usize, String)>)>, )

Set the change callback function for handling document changes

Source

pub fn highlight_interval( &self, start: usize, end: usize, theme: &HashMap<String, Style>, ) -> Vec<(usize, usize, Style)>

Return cached syntax highlights for the char range [start, end).

Source

pub fn reset_highlight_cache(&self)

Clear the cached syntax highlights so they are recomputed on next render.

Source

pub fn get_visible_cursor(&self, area: &Rect) -> Option<(u16, u16)>

Compute the cursor’s visible (x, y) cell within area, or None when the cursor is scrolled out of view.

Source

pub fn show_line_numbers(&mut self, show: bool)

Show or hide the line-number gutter.

Source

pub fn toggle_line_numbers(&mut self) -> bool

Toggle the line-number gutter; returns the new visibility.

Source

pub fn show_whitespace(&mut self, show: bool)

Show or hide visible-whitespace glyphs (space, tab, line ending).

Source

pub fn set_auto_pair(&mut self, on: bool)

Enable or disable bracket/quote auto-pairing.

Source

pub fn set_rainbow_brackets(&mut self, on: bool)

Enable or disable rainbow (depth-colored) brackets.

Source

pub fn set_eol_note(&mut self, note: Option<(usize, String)>)

Set (or clear with None) the end-of-line virtual note: (line, text) drawn dimmed after that line’s content. Used for inline git blame.

Source

pub fn set_breakpoints(&mut self, lines: Vec<usize>)

Set the debugger breakpoint lines (0-based) drawn in the gutter.

Source

pub fn set_debug_line(&mut self, line: Option<usize>)

Set (or clear) the debugger’s currently-stopped line (0-based).

Source

pub fn set_soft_wrap(&mut self, on: bool)

Enable or disable soft wrap (long lines wrap instead of scrolling).

Source

pub fn toggle_soft_wrap(&mut self) -> bool

Toggle soft wrap; returns the new state.

Source

pub fn set_indent(&mut self, indent: Option<String>)

Set the indent string inserted by Tab / the Indent action (spaces or a tab). None restores the per-language default.

Source

pub fn toggle_whitespace(&mut self) -> bool

Toggle visible-whitespace glyphs; returns the new visibility.

Source

pub fn set_whitespace_style(&mut self, style: Style)

Set the style used for visible-whitespace glyphs (typically dimmed).

Source

pub fn set_bracket_style(&mut self, style: Style)

Set the style used to highlight the bracket matching the one at the cursor.

Source

pub fn set_left_code_padding(&mut self, char_count: usize)

Set the left padding (in characters) between the gutter and the code.

Source§

impl Editor

Source

pub fn input(&mut self, key: KeyEvent, area: &Rect) -> Result<(), Error>

Handle a crossterm key event, then scroll to keep the cursor visible.

§Errors

Returns an error when an applied action fails.

Source

pub fn mouse(&mut self, mouse: MouseEvent, area: &Rect) -> Result<(), Error>

Handle a crossterm mouse event (scroll, click, drag, selection).

§Errors

Returns an error when an applied action fails.

Source

pub fn autoscroll_tick(&mut self, area: &Rect) -> bool

Repeat the last drag while the pointer is held still outside the top or bottom edge (T581). Call periodically; a no-op when no drag is in progress or the pointer is inside the view. Returns whether it acted.

Source§

impl Editor

Source

pub fn has_multi_carets(&self) -> bool

Whether more than one caret is active.

Source

pub fn clear_carets(&mut self)

Drop all extra carets, keeping just the primary cursor.

Source

pub fn caret_selections(&self) -> Vec<(usize, usize)>

Selection ranges for every caret (primary + extras), for rendering.

Source

pub fn caret_positions(&self) -> Vec<usize>

Cursor offsets for every caret (primary + extras), for rendering.

Source

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

Insert text at every caret (replacing each selection), as one undo step. Carets are processed in ascending order with a running offset shift, so each edit’s coordinates stay valid in the live buffer.

§Panics

Never in practice: the running shift only ever reflects text‘s length and prior carets’ removed spans, both bounded by the buffer this same call is editing, so the isize conversion cannot overflow.

Source

pub fn multi_delete(&mut self, forward: bool)

Delete at every caret (each selection, else one char), as one undo step.

§Panics

Never in practice: same bound as Self::multi_insert — the running shift only ever reflects removed spans within the buffer this same call is editing, so the isize conversion cannot overflow.

Source

pub fn multi_move(&mut self, dir: CaretMove, shift: bool)

Move every caret in dir (extending its selection when shift).

Source

pub fn add_next_occurrence(&mut self)

Ctrl+D: select the next occurrence of the current selection (or the word at the cursor) and add it as a new caret, which becomes primary.

Source

pub fn add_all_occurrences(&mut self)

Select every occurrence of the current selection (or the word at the cursor) in the buffer: replace any existing extra carets with one selected caret per match, the last of which becomes primary. No-op when there is only a single match.

Source

pub fn add_caret_at(&mut self, pos: usize)

Alt+click: add an extra caret at character offset pos.

Source

pub fn add_caret_above(&mut self)

Add a caret on the line above the main cursor, at the same column (clamped to that line’s length). No-op on the first line.

Source

pub fn add_caret_below(&mut self)

Add a caret on the line below the main cursor, at the same column (clamped to that line’s length). No-op on the last line.

Source

pub fn column_select(&mut self, down: bool)

Extend a column (rectangular) selection by one line: add a caret on the line past the current block frontier, spanning the same columns as the primary caret’s selection (or a bare caret when there is no selection). Columns clamp to each line’s length. No-op at the buffer’s top/bottom. The resulting carets edit together via Editor::multi_insert etc.

Source§

impl Editor

Source

pub fn cursor_up(&mut self)

Move the cursor up one line.

Source

pub fn cursor_down(&mut self)

Move the cursor down one line.

Source

pub fn cursor_left(&mut self)

Move the cursor one character to the left.

Source

pub fn cursor_right(&mut self)

Move the cursor one character to the right.

Source

pub fn select_up(&mut self)

Extend the selection one line up.

Source

pub fn select_down(&mut self)

Extend the selection one line down.

Source

pub fn select_left(&mut self)

Extend the selection one character to the left.

Source

pub fn select_right(&mut self)

Extend the selection one character to the right.

Source

pub fn cursor_start(&mut self)

Move the cursor to the very start of the buffer.

Source

pub fn cursor_end(&mut self)

Move the cursor to the very end of the buffer.

Source

pub fn select_to_start(&mut self)

Extend the selection to the start of the buffer.

Source

pub fn select_to_end(&mut self)

Extend the selection to the end of the buffer.

Source

pub fn start_of_line(&mut self)

Move the cursor to the start of the current line.

Source

pub fn end_of_line(&mut self)

Move the cursor to the end of the current line.

Source

pub fn start_of_text(&mut self)

Move to the first non-whitespace character of the line.

Source

pub fn start_of_text_toggle(&mut self)

Toggle between the first non-whitespace character and column 0.

Source

pub fn select_to_start_of_line(&mut self)

Extend the selection to the start of the current line.

Source

pub fn select_to_end_of_line(&mut self)

Extend the selection to the end of the current line.

Source

pub fn select_to_start_of_text(&mut self)

Extend the selection to the first non-whitespace character of the line.

Source

pub fn select_to_start_of_text_toggle(&mut self)

Extend the selection, toggling between the first non-whitespace character and column 0.

Source

pub fn select_line(&mut self)

Select the whole current line (including its trailing newline if any).

Source

pub fn word_right(&mut self)

Move the cursor to the start of the next word.

Source

pub fn word_left(&mut self)

Move the cursor to the start of the previous word.

Source

pub fn sub_word_right(&mut self)

Move the cursor right by one sub-word (approximated as a whole word).

Source

pub fn sub_word_left(&mut self)

Move the cursor left by one sub-word (approximated as a whole word).

Source

pub fn select_word_right(&mut self)

Extend the selection to the start of the next word.

Source

pub fn select_word_left(&mut self)

Extend the selection to the start of the previous word.

Source

pub fn select_sub_word_right(&mut self)

Extend the selection right by one sub-word (approximated as a whole word).

Source

pub fn select_sub_word_left(&mut self)

Extend the selection left by one sub-word (approximated as a whole word).

Source

pub fn delete_word_right(&mut self)

Delete from the cursor to the start of the next word.

Source

pub fn delete_word_left(&mut self)

Delete from the cursor back to the start of the previous word.

Source

pub fn delete_sub_word_right(&mut self)

Delete the next sub-word (approximated as a whole word).

Source

pub fn delete_sub_word_left(&mut self)

Delete the previous sub-word (approximated as a whole word).

Source

pub fn paragraph_next(&mut self)

Move the cursor to the start of the next paragraph.

Source

pub fn paragraph_previous(&mut self)

Move the cursor to the start of the previous paragraph.

Source

pub fn select_to_paragraph_next(&mut self)

Extend the selection to the start of the next paragraph.

Source

pub fn select_to_paragraph_previous(&mut self)

Extend the selection to the start of the previous paragraph.

Source

pub fn page_up(&mut self, view_h: usize)

Move the cursor up one page (the viewport height).

Source

pub fn page_down(&mut self, view_h: usize)

Move the cursor down one page (the viewport height).

Source

pub fn select_page_up(&mut self, view_h: usize)

Extend the selection up one page (the viewport height).

Source

pub fn select_page_down(&mut self, view_h: usize)

Extend the selection down one page (the viewport height).

Source

pub fn half_page_up(&mut self, view_h: usize)

Move the cursor up half a page.

Source

pub fn half_page_down(&mut self, view_h: usize)

Move the cursor down half a page.

Source

pub fn center(&mut self, view_h: usize)

Center the viewport on the cursor line.

Source

pub fn cursor_to_view_top(&mut self)

Move the cursor to the top/center/bottom visible line, keeping its column.

Source

pub fn cursor_to_view_center(&mut self, view_h: usize)

Move the cursor to the center visible line, keeping its column.

Source

pub fn cursor_to_view_bottom(&mut self, view_h: usize)

Move the cursor to the bottom visible line, keeping its column.

Source

pub fn insert_newline(&mut self)

Insert a newline at the cursor.

Source

pub fn insert_tab(&mut self)

Insert a tab (indent) at the cursor.

Source

pub fn backspace(&mut self)

Delete the character before the cursor.

Source

pub fn delete(&mut self)

Forward delete (the character at the cursor).

Source

pub fn undo(&mut self)

Undo the last edit.

Source

pub fn redo(&mut self)

Redo the last undone edit.

Source

pub fn copy(&mut self)

Copy the selection to the clipboard.

Source

pub fn cut(&mut self)

Cut the selection to the clipboard.

Source

pub fn paste(&mut self)

Paste the clipboard at the cursor.

Source

pub fn select_all(&mut self)

Select the entire buffer.

Source

pub fn duplicate(&mut self)

Duplicate the selection (or current line).

Source

pub fn duplicate_line(&mut self)

Duplicate the current line.

Source

pub fn delete_line(&mut self)

Delete the current line.

Source

pub fn indent_line(&mut self)

Indent the current line.

Source

pub fn outdent_line(&mut self)

Outdent the current line.

Source

pub fn indent_selection(&mut self)

Indent the selection.

Source

pub fn outdent_selection(&mut self)

Outdent the selection.

Source

pub fn copy_line(&mut self)

Copy the current line to the clipboard (without changing the selection).

Source

pub fn cut_line(&mut self)

Cut the current line to the clipboard.

Source

pub fn deselect(&mut self)

Drop the selection, keeping the cursor.

Source

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

Insert literal text (used by paste-primary fallbacks/tests).

Source§

impl Editor

Source

pub fn matching_bracket_offset(&self) -> Option<usize>

Public accessor for the matching bracket offset, used by the host to jump the cursor to a bracket’s partner (Ctrl+] / the palette).

Source§

impl Editor

Source

pub fn move_line_up(&mut self)

Move the cursor’s line up one row, swapping it with the line above. No-op on the first line. Records one undoable edit and keeps the cursor on the moved line.

Source

pub fn move_line_down(&mut self)

Move the cursor’s line down one row, swapping it with the line below. No-op on the last line. Records one undoable edit and keeps the cursor on the moved line.

Source

pub fn join_lines(&mut self)

Join the current line with the next, or — when the selection spans several lines — join all of them into one. Adjacent lines are merged with a single space, trimming the trailing space of each line and the leading space of the next. Records one undoable edit. No-op when there is nothing to join (a single line with no line below it).

Source

pub fn sort_lines(&mut self)

Sort the selected lines ascending (byte order), or the whole buffer when nothing is selected. Records one undoable edit. No-op on fewer than two lines in range.

Source

pub fn trim_trailing_whitespace(&mut self)

Strip trailing whitespace from each line in range (selection, or the whole buffer when nothing is selected).

Source

pub fn remove_duplicate_lines(&mut self)

Remove duplicate lines in range, keeping the first occurrence of each.

Source

pub fn reverse_lines(&mut self)

Reverse the order of the lines in range.

Source

pub fn shuffle_lines(&mut self)

Randomly reorder the lines in range (Fisher–Yates, seeded from the OS).

Source

pub fn sort_unique(&mut self)

Sort the lines in range ascending and drop duplicates.

Trait Implementations§

Source§

impl Widget for &Editor

Draws the main editor view in the provided area using the ratatui rendering buffer.

Renders the main editor view in four distinct layers:

  1. Line numbers and text content are drawn in the visible viewport.
  2. Syntax highlighting is overlaid on top of the text.
  3. The selection highlight is rendered above the syntax layer.
  4. User marks are rendered as the final uppermost overlay.

§Arguments

  • self - The Editor instance (as reference) to render.
  • area - The rectangular area on the terminal to draw within.
  • buf - The ratatui Buffer that represents the screen cells to draw to.
Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.

Auto Trait Implementations§

§

impl !Freeze for Editor

§

impl !RefUnwindSafe for Editor

§

impl !Send for Editor

§

impl !Sync for Editor

§

impl !UnwindSafe for Editor

§

impl Unpin for Editor

§

impl UnsafeUnpin for Editor

Blanket Implementations§

Source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Real + Zero + Arithmetics + Clone, Swp: WhitePoint<T>, Dwp: WhitePoint<T>, D: AdaptFrom<S, Swp, Dwp, T>,

Source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<T>,

👎Deprecated since 0.7.7:

replaced by palette::chromatic_adaptation::AdaptIntoUnclamped

Convert the source color to the destination color using the specified method.
Source§

fn adapt_into(self) -> D

👎Deprecated since 0.7.7:

replaced by palette::chromatic_adaptation::AdaptIntoUnclamped

Convert the source color to the destination color using the bradford method by default.
Source§

impl<T, C> AdaptIntoUnclamped<T> for C
where T: AdaptFromUnclamped<C>,

Source§

type Scalar = <T as AdaptFromUnclamped<C>>::Scalar

The number type that’s used as the color’s components.
Source§

fn adapt_into_unclamped_with<M>(self) -> T

Adapt a color of type Self into a color of type T, using the custom matrix M. Read more
Source§

fn adapt_into_unclamped(self) -> T
where Bradford: LmsToXyz<Self::Scalar> + XyzToLms<Self::Scalar>,

Adapt a color of type Self into a color of type T, using the Bradford matrix. Read more
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, C> ArraysFrom<C> for T
where C: IntoArrays<T>,

Source§

fn arrays_from(colors: C) -> T

Cast a collection of colors into a collection of arrays.
Source§

impl<T, C> ArraysInto<C> for T
where C: FromArrays<T>,

Source§

fn arrays_into(self) -> C

Cast this collection of arrays into a collection of colors.
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for U
where T: FromCam16Unclamped<WpParam, U>,

Source§

type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T, C> ComponentsFrom<C> for T
where C: IntoComponents<T>,

Source§

fn components_from(colors: C) -> T

Cast a collection of colors into a collection of color components.
Source§

impl<T, C> ComponentsInto<C> for T

Source§

fn components_into(self) -> C

Cast this collection of color components into a collection of colors. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromAngle<T> for T

Source§

fn from_angle(angle: T) -> T

Performs a conversion from angle.
Source§

impl<T, U> FromStimulus<U> for T
where U: IntoStimulus<T>,

Source§

fn from_stimulus(other: U) -> T

Converts other into Self, while performing the appropriate scaling, rounding and clamping.
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> IntoAngle<U> for T
where U: FromAngle<T>,

Source§

fn into_angle(self) -> U

Performs a conversion into T.
Source§

impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for U
where T: Cam16FromUnclamped<WpParam, U>,

Source§

type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<T, U> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

Source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoStimulus<T> for T

Source§

fn into_stimulus(self) -> T

Converts self into T, while performing the appropriate scaling, rounding and clamping.
Source§

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

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T, C> TryComponentsInto<C> for T
where C: TryFromComponents<T>,

Source§

type Error = <C as TryFromComponents<T>>::Error

The error for when try_into_colors fails to cast.
Source§

fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>

Try to cast this collection of color components into a collection of colors. Read more
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
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.
Source§

impl<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

Source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
Source§

impl<C, U> UintsFrom<C> for U
where C: IntoUints<U>,

Source§

fn uints_from(colors: C) -> U

Cast a collection of colors into a collection of unsigned integers.
Source§

impl<C, U> UintsInto<C> for U
where C: FromUints<U>,

Source§

fn uints_into(self) -> C

Cast this collection of unsigned integers into a collection of colors.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V