Skip to main content

EditorHook

Trait EditorHook 

Source
pub trait EditorHook: 'static {
    // Provided methods
    fn on_key(
        &mut self,
        _ctx: &mut HookContext<'_>,
        _event: &KeyEvent,
    ) -> HookOutcome { ... }
    fn on_search_action(
        &mut self,
        _ctx: &mut HookContext<'_>,
        _action: SearchAction,
    ) -> HookOutcome { ... }
    fn before_insert(
        &mut self,
        _ctx: &mut HookContext<'_>,
        _text: char,
    ) -> HookOutcome { ... }
    fn after_edit(&mut self, _buffer: &mut EditorBuffer) { ... }
    fn on_selection_change(
        &mut self,
        _buffer: &EditorBuffer,
        _selection: Option<&Selection>,
    ) { ... }
    fn on_click(
        &mut self,
        _ctx: &mut HookContext<'_>,
        _row: usize,
        _col: usize,
    ) -> HookOutcome { ... }
    fn context_menu_items(
        &self,
        _ctx: &ContextMenuContext<'_>,
    ) -> Vec<ContextMenuItem> { ... }
    fn on_context_menu_action(
        &mut self,
        _ctx: &mut HookContext<'_>,
        _id: &str,
    ) -> HookOutcome { ... }
    fn status_text(&self) -> Option<&str> { ... }
    fn search_snapshot(&self) -> Option<SearchSnapshot> { ... }
}
Expand description

Trait for intercepting input events, mutating buffer state, and extending editor behaviors.

Provided Methods§

Source

fn on_key( &mut self, _ctx: &mut HookContext<'_>, _event: &KeyEvent, ) -> HookOutcome

Intercepts a key press before standard editor processing.

Source

fn on_search_action( &mut self, _ctx: &mut HookContext<'_>, _action: SearchAction, ) -> HookOutcome

Handles a synthetic search-panel action (prompt-bar clicks).

Pointer chrome cannot produce a KeyCode, so actions travel here instead of through on_key. The default passes through; SearchHook implements this.

Source

fn before_insert( &mut self, _ctx: &mut HookContext<'_>, _text: char, ) -> HookOutcome

Intercepts text insertion before it is written to the buffer.

Source

fn after_edit(&mut self, _buffer: &mut EditorBuffer)

Called immediately after any buffer mutation (typing, deletions, paste, undo/redo).

Source

fn on_selection_change( &mut self, _buffer: &EditorBuffer, _selection: Option<&Selection>, )

Called whenever the cursor offset or selection range changes.

Source

fn on_click( &mut self, _ctx: &mut HookContext<'_>, _row: usize, _col: usize, ) -> HookOutcome

Intercepts a mouse click at a given buffer line and source byte column.

row is the zero-based buffer row. col is the source byte offset within that line’s text (pre-concealment coordinates, clamped to the line length). Hooks handling interactive elements (e.g. Markdown task checkboxes) should operate on row directly rather than the current cursor row, preserve the cursor offset when appropriate, and return Consumed to halt propagation.

Source

fn context_menu_items( &self, _ctx: &ContextMenuContext<'_>, ) -> Vec<ContextMenuItem>

Contributes right-click context menu rows for the given click.

Rows append after the built-in edit actions (Cut/Copy/Paste/…); returning an item with a well-known id (e.g. "copy") overrides that default in place. The default is no rows.

Source

fn on_context_menu_action( &mut self, _ctx: &mut HookContext<'_>, _id: &str, ) -> HookOutcome

Handles activation of a context menu row by id.

Runs before the built-in edit dispatch; return Consumed to halt (including to suppress a default with the same id). The default passes through to built-in handling.

Source

fn status_text(&self) -> Option<&str>

Returns a human-readable status or active mode name, if any.

Source

fn search_snapshot(&self) -> Option<SearchSnapshot>

Returns a live search-panel snapshot for renderers (toggles, matches).

Hooks without a prompt-driven search return None (the default), in which case editors hide search chrome. crate::SearchHook implements this; composite hooks (e.g. vim) forward their owned hook.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§