Skip to main content

MarkdownEditor

Struct MarkdownEditor 

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

Coordinated markdown editor that owns both the text Editor and the MarkdownTree. After every mutation that changes text content, the tree is automatically synced via set_source(). This is the single coordination point — callers should never need to manually sync.

Implementations§

Source§

impl MarkdownEditor

Source

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

Create a new markdown editor with the given text.

Source

pub fn empty() -> Self

Create an empty markdown editor.

Source

pub fn editor(&self) -> &Editor

Immutable access to the inner Editor.

Source

pub fn editor_mut(&mut self) -> &mut Editor

Mutable access to the inner Editor.

Important: If you mutate the editor text through this reference (e.g., via MarkdownCommands, InputRules, or direct calls to insert(), backspace(), undo(), redo(), etc.), you must call sync_tree() afterward to keep the tree in sync.

Source

pub fn buffer(&self) -> &Buffer

Immutable access to the inner Buffer.

Source

pub fn version(&self) -> u64

Document version, incremented on every edit.

Source

pub fn tree(&self) -> &MarkdownTree

Immutable access to the MarkdownTree.

Source

pub fn sync_tree(&mut self)

Full reparse of the tree from the editor’s current text. Call this after using editor_mut() to make direct mutations.

Source

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

Insert text at the cursor. If there’s a selection, replace it.

Source

pub fn backspace(&mut self)

Delete the character before the cursor (backspace).

Source

pub fn delete_forward(&mut self)

Delete the character after the cursor (forward delete).

Source

pub fn insert_newline(&mut self)

Insert a newline at the cursor.

Source

pub fn undo(&mut self)

Undo the last transaction.

Source

pub fn redo(&mut self)

Redo the last undone transaction.

Source

pub fn delete_selection(&mut self)

Delete the current selection. No-op if cursor only.

Source

pub fn apply_transaction(&mut self, tx: Transaction)

Apply a pre-built transaction atomically.

Source

pub fn indent(&mut self)

Insert a tab (2 spaces) at the cursor, or indent all selected lines.

Source

pub fn outdent(&mut self)

Remove one level of indentation from the current or selected lines.

Source

pub fn duplicate_lines(&mut self)

Duplicate the current line or all selected lines.

Source

pub fn delete_word_back(&mut self)

Delete from cursor to start of previous word (Ctrl+Backspace).

Source

pub fn delete_word_forward(&mut self)

Delete from cursor to end of next word (Ctrl+Delete).

Source

pub fn text(&self) -> String

Get the full text content.

Source

pub fn cursor(&self) -> Position

Get the current cursor position.

Source

pub fn selection(&self) -> Selection

Get the current selection.

Source

pub fn selected_text(&self) -> String

Get the selected text, or empty string if cursor only.

Source

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

Set the cursor to a position, collapsing any selection.

Source

pub fn set_selection(&mut self, anchor: Position, head: Position)

Set a selection range.

Source

pub fn select_all(&mut self)

Select all text.

Source

pub fn move_left(&mut self)

Move cursor left by one character.

Source

pub fn move_right(&mut self)

Move cursor right by one character.

Source

pub fn move_up(&mut self)

Move cursor up by one line.

Source

pub fn move_down(&mut self)

Move cursor down by one line.

Source

pub fn move_word_left(&mut self)

Move cursor left to the start of the previous word.

Source

pub fn move_word_right(&mut self)

Move cursor right to the end of the next word.

Source

pub fn move_to_line_start(&mut self)

Move cursor to start of current line.

Source

pub fn move_to_line_end(&mut self)

Move cursor to end of current line.

Source

pub fn move_to_start(&mut self)

Move cursor to start of document.

Source

pub fn move_to_end(&mut self)

Move cursor to end of document.

Source

pub fn extend_selection_left(&mut self)

Extend selection one character left (Shift+Left).

Source

pub fn extend_selection_right(&mut self)

Extend selection one character right (Shift+Right).

Source

pub fn extend_selection_up(&mut self)

Extend selection up one line (Shift+Up).

Source

pub fn extend_selection_down(&mut self)

Extend selection down one line (Shift+Down).

Source

pub fn extend_selection(&mut self, head: Position)

Extend selection to a specific position.

Source

pub fn extend_selection_word_left(&mut self)

Extend selection to word boundary left (Ctrl+Shift+Left).

Source

pub fn extend_selection_word_right(&mut self)

Extend selection to word boundary right (Ctrl+Shift+Right).

Source

pub fn extend_selection_to_line_start(&mut self)

Extend selection to line start (Shift+Home).

Source

pub fn extend_selection_to_line_end(&mut self)

Extend selection to line end (Shift+End).

Source

pub fn extend_selection_to_start(&mut self)

Extend selection to document start (Ctrl+Shift+Home).

Source

pub fn extend_selection_to_end(&mut self)

Extend selection to document end (Ctrl+Shift+End).

Source

pub fn select_word(&mut self)

Select the word at the cursor (double-click behavior).

Source

pub fn select_line(&mut self)

Select the entire current line (triple-click behavior).

Source

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

Move cursor up by N lines (PageUp).

Source

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

Move cursor down by N lines (PageDown).

Source

pub fn is_dirty(&self) -> bool

Check if the editor has unsaved changes.

Source

pub fn mark_clean(&mut self)

Mark the editor as clean (e.g., after saving).

Source

pub fn can_undo(&self) -> bool

Check if undo is available.

Source

pub fn can_redo(&self) -> bool

Check if redo is available.

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.