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
impl Editor
pub fn new(lang: &str, text: &str, theme: Vec<(&str, &str)>) -> Result<Self>
pub fn new_with_highlights( lang: &str, text: &str, theme: Vec<(&str, &str)>, custom_highlights: Option<HashMap<String, String>>, ) -> Result<Self>
pub fn focus(&mut self, area: &Rect)
Sourcepub fn handle_mouse_down(&mut self, cursor: usize)
pub fn handle_mouse_down(&mut self, cursor: usize)
Handles a mouse button press at the given cursor position, updating selection and click state.
Sourcepub fn handle_mouse_drag(&mut self, cursor: usize)
pub fn handle_mouse_drag(&mut self, cursor: usize)
Handles a mouse drag event at the given cursor position, extending the selection.
Sourcepub fn cursor_from_mouse(
&self,
mouse_x: u16,
mouse_y: u16,
area: &Rect,
) -> Option<usize>
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.
Sourcepub fn clear_selection(&mut self)
pub fn clear_selection(&mut self)
Clears any active selection.
Sourcepub fn extend_selection(&mut self, new_cursor: usize)
pub fn extend_selection(&mut self, new_cursor: usize)
Extends or starts a selection from the current cursor to new_cursor.
Sourcepub fn selection_anchor(&self) -> usize
pub fn selection_anchor(&self) -> usize
Returns the selection anchor position, or the cursor if no selection exists.
pub fn apply<A: Action>(&mut self, action: A)
pub fn set_content(&mut self, content: &str)
pub fn set_original_code(&mut self, content: &str) -> Result<()>
pub fn clear_original_code(&mut self)
pub fn has_diff(&self) -> bool
pub fn set_diff_enabled(&mut self, enabled: bool)
pub fn is_diff_enabled(&self) -> bool
pub fn set_diff_focus_enabled(&mut self, enabled: bool)
pub fn toggle_diff_focus(&mut self)
pub fn set_diff_focus_context(&mut self, context_lines: usize)
pub fn set_diff_expand_amount(&mut self, amount: usize)
pub fn set_diff_options(&mut self, options: DiffOptions)
pub fn diff_options(&self) -> DiffOptions
pub fn apply_batch(&mut self, batch: &EditBatch)
pub fn set_cursor(&mut self, cursor: usize)
Sourcepub fn toggle_fold_at_line(&mut self, line_idx: usize) -> bool
pub fn toggle_fold_at_line(&mut self, line_idx: usize) -> bool
Toggles the Rust Tree-sitter fold that begins on line_idx.
pub fn toggle_fold_at_cursor(&mut self) -> bool
pub fn set_code_folding_enabled(&mut self, enabled: bool)
pub fn is_code_folding_enabled(&self) -> bool
pub fn set_code_folding_options(&mut self, options: CodeFoldingOptions)
pub fn code_folding_options(&self) -> CodeFoldingOptions
pub fn fit_cursor(&mut self)
pub fn scroll_up(&mut self)
pub fn scroll_down(&mut self, area_height: usize)
pub fn build_theme(theme: &Vec<(&str, &str)>) -> Theme
pub fn get_content(&self) -> String
pub fn get_content_slice(&self, start: usize, end: usize) -> String
pub fn get_cursor(&self) -> usize
pub fn set_clipboard(&mut self, text: &str) -> Result<()>
pub fn get_clipboard(&self) -> Result<String>
pub fn set_marks(&mut self, marks: Vec<(usize, usize, &str)>)
pub fn remove_marks(&mut self)
pub fn has_marks(&self) -> bool
pub fn get_marks(&self) -> Option<&Vec<(usize, usize, Color)>>
pub fn get_selection_text(&mut self) -> Option<String>
pub fn get_selection(&mut self) -> Option<Selection>
pub fn set_selection(&mut self, selection: Option<Selection>)
pub fn set_offset_y(&mut self, offset_y: usize)
pub fn set_offset_x(&mut self, offset_x: usize)
pub fn get_offset_y(&self) -> usize
pub fn get_offset_x(&self) -> usize
pub fn code_mut(&mut self) -> &mut Code
pub fn code_ref(&self) -> &Code
Sourcepub fn set_change_callback(
&mut self,
callback: Box<dyn Fn(Vec<(usize, usize, usize, usize, String)>)>,
)
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
pub fn highlight_interval( &self, start: usize, end: usize, theme: &Theme, ) -> Vec<(usize, usize, Style)>
pub fn highlight_interval_original( &self, start: usize, end: usize, theme: &Theme, ) -> Vec<(usize, usize, Style)>
pub fn word_highlight_ranges(&self) -> Vec<(usize, usize)>
pub fn set_word_highlight_enabled(&mut self, enabled: bool)
pub fn word_highlight_enabled(&self) -> bool
pub fn reset_highlight_cache(&mut self)
pub fn get_line_diff( &self, orig_idx: usize, curr_idx: usize, is_ghost: bool, ) -> Vec<(usize, usize)>
Source§impl Editor
impl Editor
Sourcepub fn get_visible_cursor(&self, area: &Rect) -> Option<(u16, u16)>
pub fn get_visible_cursor(&self, area: &Rect) -> Option<(u16, u16)>
calculates visible cursor position
pub fn show_line_numbers(&mut self, show: bool)
pub fn set_left_code_padding(&mut self, char_count: usize)
Trait Implementations§
Source§impl Widget for &Editor
Draws the main editor view in the provided area using the ratatui rendering buffer.
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- TheEditorinstance (as reference) to render.area- The rectangular area on the terminal to draw within.buf- The ratatuiBufferthat represents the screen cells to draw to.
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> 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
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 more