Skip to main content

Editor

Struct Editor 

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

Core text editor combining Rope storage with cursor management.

Provides insert/delete/move operations with grapheme-aware cursor handling, undo/redo, and selection support. Cursor is always kept in valid bounds.

Implementations§

Source§

impl Editor

Source

pub fn new() -> Self

Create an empty editor.

Source

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

Create an editor with initial text. Cursor starts at the end.

Source

pub fn set_max_history(&mut self, max: usize)

Set the maximum undo history depth.

Source

pub fn set_max_undo_size(&mut self, bytes: usize)

Set the maximum undo history size in bytes.

Source

pub fn text(&self) -> String

Get the full text content as a string.

Source

pub fn rope(&self) -> &Rope

Get a reference to the underlying rope.

Source

pub fn cursor(&self) -> CursorPosition

Get the current cursor position.

Source

pub fn set_cursor(&mut self, pos: CursorPosition)

Set cursor position (will be clamped to valid bounds). Clears selection.

Source

pub fn selection(&self) -> Option<Selection>

Current selection, if any.

Source

pub fn can_undo(&self) -> bool

Whether undo is available.

Source

pub fn can_redo(&self) -> bool

Whether redo is available.

Source

pub fn is_empty(&self) -> bool

Check if the editor is empty.

Source

pub fn line_count(&self) -> usize

Number of lines in the buffer.

Source

pub fn line_text(&self, line: usize) -> Option<String>

Get the text of a specific line (without trailing newline).

Source

pub fn insert_char(&mut self, ch: char)

Insert a single character at the cursor position.

Source

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

Insert text at the cursor position. Deletes selection first if active.

Control characters (except newline and tab) are stripped to prevent terminal corruption.

Source

pub fn insert_newline(&mut self)

Insert a newline at the cursor position.

Source

pub fn delete_backward(&mut self) -> bool

Delete the character before the cursor (backspace). Deletes selection if active.

Returns true if a character was deleted.

Source

pub fn delete_forward(&mut self) -> bool

Delete the character after the cursor (delete key). Deletes selection if active.

Returns true if a character was deleted.

Source

pub fn delete_word_backward(&mut self) -> bool

Delete the word before the cursor (Ctrl+Backspace).

Returns true if any text was deleted.

Source

pub fn delete_to_end_of_line(&mut self) -> bool

Delete from cursor to end of line (Ctrl+K).

Returns true if any text was deleted.

Source

pub fn undo(&mut self) -> bool

Undo the last edit operation.

Source

pub fn redo(&mut self) -> bool

Redo the last undone operation.

Source

pub fn move_left(&mut self)

Move cursor left by one grapheme.

Source

pub fn move_right(&mut self)

Move cursor right by one grapheme.

Source

pub fn move_up(&mut self)

Move cursor up one line.

Source

pub fn move_down(&mut self)

Move cursor down one line.

Source

pub fn move_word_left(&mut self)

Move cursor left by one word.

Source

pub fn move_word_right(&mut self)

Move cursor right by one word.

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_document_start(&mut self)

Move cursor to start of document.

Source

pub fn move_to_document_end(&mut self)

Move cursor to end of document.

Source

pub fn select_left(&mut self)

Extend selection left by one grapheme.

Source

pub fn select_right(&mut self)

Extend selection right by one grapheme.

Source

pub fn select_up(&mut self)

Extend selection up one line.

Source

pub fn select_down(&mut self)

Extend selection down one line.

Source

pub fn select_word_left(&mut self)

Extend selection left by one word.

Source

pub fn select_word_right(&mut self)

Extend selection right by one word.

Source

pub fn select_all(&mut self)

Select all text.

Source

pub fn clear_selection(&mut self)

Clear current selection without moving cursor.

Source

pub fn selected_text(&self) -> Option<String>

Get selected text, if any non-empty selection exists.

Source

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

Replace all content and reset cursor to end. Clears undo history.

Source

pub fn clear(&mut self)

Clear all content and reset cursor. Clears undo history.

Trait Implementations§

Source§

impl Clone for Editor

Source§

fn clone(&self) -> Editor

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Editor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Editor

Source§

fn default() -> Self

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more