pub struct Editor { /* private fields */ }Expand description
Editor - A multi-line text editor component.
Implementations§
Source§impl Editor
impl Editor
Sourcepub fn new(
options: EditorOptions,
style: EditorStyle,
keybindings: Arc<Keybindings>,
) -> Self
pub fn new( options: EditorOptions, style: EditorStyle, keybindings: Arc<Keybindings>, ) -> Self
Create a new editor with options.
Sourcepub fn get_text(&self) -> String
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.
Sourcepub fn get_expanded_text(&self) -> String
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.
Sourcepub fn handle_paste(&self, text: &str)
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.
Sourcepub fn on_submit(&self, callback: Arc<dyn Fn(&str) + Send + Sync>)
pub fn on_submit(&self, callback: Arc<dyn Fn(&str) + Send + Sync>)
Set callback for when text is submitted (Enter pressed).
Sourcepub fn on_change(&self, callback: Arc<dyn Fn(&str) + Send + Sync>)
pub fn on_change(&self, callback: Arc<dyn Fn(&str) + Send + Sync>)
Set callback for when text changes.
Sourcepub fn cursor_position(&self) -> (usize, usize)
pub fn cursor_position(&self) -> (usize, usize)
Get cursor position.
Sourcepub fn set_cursor(&self, row: usize, col: usize)
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.
Sourcepub fn undo(&self)
pub fn undo(&self)
Undo the last mutation (Ctrl+-). Restores the prior snapshot; the undone state moves to the redo stack for Ctrl+R.
Sourcepub fn yank(&self)
pub fn yank(&self)
Yank (paste) the most recent kill at the cursor (Ctrl+Y). Replaces an active selection.
Sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Whether a selection is active.
Sourcepub fn selected_text(&self) -> Option<String>
pub fn selected_text(&self) -> Option<String>
The selected text (“\n”-joined across rows), if any.
Sourcepub fn copy_selection(&self) -> bool
pub fn copy_selection(&self) -> bool
Copy the selection onto the kill ring (Ctrl+C). No-op without one.
Sourcepub fn cut_selection(&self) -> bool
pub fn cut_selection(&self) -> bool
Cut the selection (copy + delete, Ctrl+X). Returns whether anything was cut.
Sourcepub fn insert(&self, text: &str)
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).
Sourcepub fn set_border_color(&self, color: Option<Color>)
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.
Sourcepub fn border_color(&self) -> Option<Color>
pub fn border_color(&self) -> Option<Color>
The current explicit border color, if any.
Sourcepub fn set_working(&self, working: Option<WorkingState>)
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.
Sourcepub fn working(&self) -> Option<WorkingState>
pub fn working(&self) -> Option<WorkingState>
Get the current working state, if any.
Sourcepub fn handle_key(&self, key: KeyEvent) -> bool
pub fn handle_key(&self, key: KeyEvent) -> bool
Handle keyboard input.