Skip to main content

Editor

Struct Editor 

Source
pub struct Editor { /* 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<Self>

Source

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

Source

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

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 expand_hidden_diff_at_mouse( &mut self, mouse_x: u16, mouse_y: u16, area: &Rect, ) -> bool

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: Action>(&mut self, action: A)

Source

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

Source

pub fn set_original_code(&mut self, content: &str) -> Result<()>

Source

pub fn clear_original_code(&mut self)

Source

pub fn has_diff(&self) -> bool

Source

pub fn set_diff_enabled(&mut self, enabled: bool)

Source

pub fn is_diff_enabled(&self) -> bool

Source

pub fn set_diff_focus_enabled(&mut self, enabled: bool)

Source

pub fn toggle_diff_focus(&mut self)

Source

pub fn set_diff_focus_context(&mut self, context_lines: usize)

Source

pub fn set_diff_expand_amount(&mut self, amount: usize)

Source

pub fn set_diff_options(&mut self, options: DiffOptions)

Source

pub fn diff_options(&self) -> DiffOptions

Source

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

Source

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

Source

pub fn toggle_fold_at_line(&mut self, line_idx: usize) -> bool

Toggles the Rust Tree-sitter fold that begins on line_idx.

Source

pub fn toggle_fold_at_cursor(&mut self) -> bool

Source

pub fn set_code_folding_enabled(&mut self, enabled: bool)

Source

pub fn is_code_folding_enabled(&self) -> bool

Source

pub fn set_code_folding_options(&mut self, options: CodeFoldingOptions)

Source

pub fn code_folding_options(&self) -> CodeFoldingOptions

Source

pub fn fit_cursor(&mut self)

Source

pub fn scroll_up(&mut self)

Source

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

Source

pub fn build_theme(theme: &Vec<(&str, &str)>) -> Theme

Source

pub fn get_content(&self) -> String

Source

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

Source

pub fn get_cursor(&self) -> usize

Source

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

Source

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

Source

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

Source

pub fn remove_marks(&mut self)

Source

pub fn has_marks(&self) -> bool

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn get_offset_y(&self) -> usize

Source

pub fn get_offset_x(&self) -> usize

Source

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

Source

pub fn code_ref(&self) -> &Code

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: &Theme, ) -> Vec<(usize, usize, Style)>

Source

pub fn highlight_interval_original( &self, start: usize, end: usize, theme: &Theme, ) -> Vec<(usize, usize, Style)>

Source

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

Source

pub fn set_word_highlight_enabled(&mut self, enabled: bool)

Source

pub fn word_highlight_enabled(&self) -> bool

Source

pub fn reset_highlight_cache(&mut self)

Source

pub fn get_line_diff( &self, orig_idx: usize, curr_idx: usize, is_ghost: bool, ) -> Vec<(usize, usize)>

Source§

impl Editor

Source

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

calculates visible cursor position

Source

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

Source

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

Source§

impl Editor

Source

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

Source

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

Trait Implementations§

Source§

impl Widget for &Editor

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

Renders visible [VisualRow]s, including fold separators and deleted diff rows. Added and deleted rows receive a diff background before syntax highlighting is applied. Selections and user marks are then drawn over real editor rows.

§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 Forget for Editor

§

impl Move for Editor

§

impl Unpin for Editor

§

impl UnsafeUnpin for Editor

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.