Skip to main content

EditBuffer

Struct EditBuffer 

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

Text buffer with editing operations, cursor, and undo/redo.

EditBuffer is the primary type for text editing. It tracks cursor position, maintains undo/redo history, and provides operations for:

  • Cursor movement: Lines, words, characters, document bounds
  • Text editing: Insert, delete, backspace with cursor tracking
  • Line operations: Duplicate, move, delete lines
  • History: Grouped undo/redo with configurable depth limit

§History Management

Edit operations are grouped automatically. Call commit to force a group boundary (e.g., after a pause in typing). The history depth is bounded (default 1000 groups) to limit memory usage.

Implementations§

Source§

impl EditBuffer

Source

pub fn new() -> Self

Create a new empty edit buffer.

Source

pub fn with_text(text: &str) -> Self

Create an edit buffer with initial text.

Source

pub fn with_max_history_depth(max_depth: usize) -> Self

Create an edit buffer with a custom maximum undo history depth.

The default is 1000 undo groups. Set a lower value for memory-constrained environments or a higher value for documents that need extensive undo history.

Source

pub fn set_max_history_depth(&mut self, max_depth: usize)

Set the maximum undo history depth.

If the current history exceeds the new depth, oldest entries will be pruned on the next commit.

Source

pub fn max_history_depth(&self) -> usize

Get the current maximum undo history depth.

Source

pub fn buffer(&self) -> &TextBuffer

Get the underlying text buffer.

Source

pub fn text(&self) -> String

Get the full text content.

Source

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

Replace the entire text, resetting cursor and history.

Source

pub fn buffer_mut(&mut self) -> &mut TextBuffer

Get mutable access to the text buffer.

Source

pub fn highlighted_buffer(&self) -> &HighlightedBuffer

Get the highlighted buffer.

Source

pub fn highlighted_buffer_mut(&mut self) -> &mut HighlightedBuffer

Get mutable access to the highlighted buffer.

Source

pub fn cursor(&self) -> Cursor

Get the current cursor position.

Source

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

Set the cursor position.

Source

pub fn set_cursor_by_offset(&mut self, offset: usize)

Set the cursor by character offset.

Source

pub fn get_cursor_position(&self) -> CursorPosition

Get cursor position info.

Source

pub fn move_left(&mut self)

Move cursor left.

Source

pub fn move_right(&mut self)

Move cursor right.

Source

pub fn move_up(&mut self)

Move cursor up.

Source

pub fn move_down(&mut self)

Move cursor down.

Source

pub fn move_to_line_start(&mut self)

Move cursor to start of line.

Source

pub fn move_to_line_end(&mut self)

Move cursor to end of line.

Source

pub fn move_to(&mut self, row: usize, col: usize)

Move to specific row and column.

Source

pub fn goto_line(&mut self, row: usize)

Jump to a specific line (start of line).

Source

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

Insert text at cursor.

Source

pub fn delete_backward(&mut self)

Delete character before cursor.

Source

pub fn delete_forward(&mut self)

Delete character after cursor.

Source

pub fn delete_range(&mut self, start: Cursor, end: Cursor)

Delete a range between two cursors.

Source

pub fn delete_range_offsets(&mut self, start: usize, end: usize)

Delete a range between character offsets.

Source

pub fn delete_line(&mut self)

Delete the current line (including trailing newline if present).

Source

pub fn duplicate_line(&mut self)

Duplicate the current line (insert copy below).

Source

pub fn move_line_up(&mut self)

Move the current line up (swap with the line above).

Source

pub fn move_line_down(&mut self)

Move the current line down (swap with the line below).

Source

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

Replace the entire text, clearing history.

Source

pub fn get_next_word_boundary(&self) -> usize

Get the next word boundary (character offset).

Source

pub fn get_prev_word_boundary(&self) -> usize

Get the previous word boundary (character offset).

Source

pub fn move_word_right(&mut self)

Move cursor to the next word boundary.

Source

pub fn move_word_left(&mut self)

Move cursor to the previous word boundary.

Source

pub fn delete_word_forward(&mut self)

Delete from cursor to the next word boundary.

Source

pub fn delete_word_backward(&mut self)

Delete from cursor to the previous word boundary.

Source

pub fn get_eol(&self) -> usize

Get end of line offset for current line.

Source

pub fn undo(&mut self) -> bool

Undo the last edit.

Source

pub fn redo(&mut self) -> bool

Redo the last undone edit.

Source

pub fn can_undo(&self) -> bool

Check if undo is available.

Source

pub fn can_redo(&self) -> bool

Check if redo is available.

Source

pub fn commit(&mut self)

Commit current edits as an undo group.

Source

pub fn clear_history(&mut self)

Clear the undo/redo history.

This removes all undo and redo entries. Useful when loading new content where previous history is no longer relevant.

Trait Implementations§

Source§

impl Default for EditBuffer

Source§

fn default() -> EditBuffer

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.