Skip to main content

Editor

Struct Editor 

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

Editor - A multi-line text editor component.

Implementations§

Source§

impl Editor

Source

pub fn new( options: EditorOptions, style: EditorStyle, keybindings: Arc<Keybindings>, ) -> Self

Create a new editor with options.

Source

pub fn simple() -> Self

Create a new editor with default options.

Source

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

Set the text content.

Source

pub fn get_text(&self) -> String

Get the text content as shown: folded large pastes appear as their [paste #id …] marker, not their full body. This is the right source for UI state that reasons about what is on screen (autocomplete, empty-checks). Use Self::get_expanded_text for anything that must see the user’s real content.

Source

pub fn get_expanded_text(&self) -> String

Get the text content with folded pastes expanded (upstream’s getExpandedText): every [paste #id …] marker is replaced by the full pasted body. Submission, the external editor and extension reads all go through here so a folded paste is never sent truncated.

Source

pub fn handle_paste(&self, text: &str)

Fold a pasted block: short pastes are inserted verbatim; a block over the size threshold is stashed and replaced by a [paste #id …] marker so the input box stays readable. Mirrors upstream’s handlePaste (fold when >10 lines or >1000 chars).

A single-line pasted file path is special-cased by the caller (image attachment), so this only handles text.

Source

pub fn clear(&self)

Clear the editor.

Source

pub fn on_submit(&self, callback: Arc<dyn Fn(&str) + Send + Sync>)

Set callback for when text is submitted (Enter pressed).

Source

pub fn on_change(&self, callback: Arc<dyn Fn(&str) + Send + Sync>)

Set callback for when text changes.

Source

pub fn cursor_position(&self) -> (usize, usize)

Get cursor position.

Source

pub fn set_cursor(&self, row: usize, col: usize)

Set the cursor position (clamped to text bounds), clearing any in-progress selection. Used by autocomplete to place the caret after accepting a suggestion (set_text resets the caret to the start).

col is interpreted as a byte offset (callers in the autocomplete path pass byte indices from String::len/char_indices) and snapped to the nearest preceding char boundary so multibyte input never lands mid-character.

Source

pub fn undo(&self)

Undo the last mutation (Ctrl+-). Restores the prior snapshot; the undone state moves to the redo stack for Ctrl+R.

Source

pub fn redo(&self)

Redo the last undone mutation (Ctrl+R).

Source

pub fn yank(&self)

Yank (paste) the most recent kill at the cursor (Ctrl+Y). Replaces an active selection.

Source

pub fn yank_pop(&self)

Yank-pop: rotate the kill ring and yank the next entry (Alt+Y).

Source

pub fn has_selection(&self) -> bool

Whether a selection is active.

Source

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

The selected text (“\n”-joined across rows), if any.

Source

pub fn copy_selection(&self) -> bool

Copy the selection onto the kill ring (Ctrl+C). No-op without one.

Source

pub fn cut_selection(&self) -> bool

Cut the selection (copy + delete, Ctrl+X). Returns whether anything was cut.

Source

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

Insert text at cursor position. Replaces an active selection (one undo step: the snapshot is taken before the selection is deleted).

Source

pub fn set_border_color(&self, color: Option<Color>)

Set an explicit top/bottom border color. None restores the theme’s default border color. Mirrors upstream’s editor.borderColor.

Source

pub fn border_color(&self) -> Option<Color>

The current explicit border color, if any.

Source

pub fn set_working(&self, working: Option<WorkingState>)

Set the working state. When Some, shows a spinner + elapsed time + message inside the top border. When None, shows the normal border.

Source

pub fn working(&self) -> Option<WorkingState>

Get the current working state, if any.

Source

pub fn handle_key(&self, key: KeyEvent) -> bool

Handle keyboard input.

Trait Implementations§

Source§

impl Component for Editor

Source§

fn render(&self, width: usize) -> Vec<String>

Render the component to lines for the given viewport width. Read more
Source§

fn invalidate(&self)

Invalidate any cached rendering state. Called when theme changes or when component needs to re-render from scratch.
Source§

fn handle_input(&self, _data: &str) -> bool

Optional handler for keyboard input when component has focus. Read more
Source§

fn as_any(&self) -> &dyn Any

Downcast to Any for runtime type checking. This enables the layout system to check for LayoutNodeProvider.
Source§

fn wants_key_release(&self) -> bool

If true, component receives key release events (Kitty protocol). Default is false - release events are filtered out.
Source§

impl Focusable for Editor

Source§

fn set_focused(&self, focused: bool)

Set by TUI when focus changes. Component should emit CURSOR_MARKER when true.
Source§

fn is_focused(&self) -> bool

Check if the component is currently focused.

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

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

fn try_from(value: U) -> Result<T, !>

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.