pub struct CodeEditor { /* private fields */ }Expand description
High-level code editor managing buffer state, multi-cursors, incremental syntax, search/replace, folding, diagnostics, theming, and virtualized rendering.
Implementations§
Source§impl CodeEditor
impl CodeEditor
Sourcepub fn new(content: &str, language: Language) -> Self
pub fn new(content: &str, language: Language) -> Self
Constructs a new code editor with initial source code and language syntax.
Sourcepub fn edit_revision(&self) -> u64
pub fn edit_revision(&self) -> u64
Monotonic counter incremented only when document buffer text actually mutates.
Non-mutating shortcuts (Ctrl+F, Ctrl+H, Ctrl+A, Ctrl+C, navigation, folding)
leave edit_revision() unchanged so on_change callbacks never fire falsely.
Sourcepub fn highlighter(&self) -> &SyntaxHighlighter
pub fn highlighter(&self) -> &SyntaxHighlighter
Accesses the active syntax highlighter.
Sourcepub fn highlighter_mut(&mut self) -> &mut SyntaxHighlighter
pub fn highlighter_mut(&mut self) -> &mut SyntaxHighlighter
Accesses the active syntax highlighter mutably.
Sourcepub fn set_language(&mut self, language: Language)
pub fn set_language(&mut self, language: Language)
Changes the syntax language and re-parses the AST directly from the rope buffer.
Sourcepub fn reparse(&mut self)
pub fn reparse(&mut self)
Re-parses the document incrementally with the active Tree-Sitter grammar via zero-copy rope slices.
Sourcepub fn buffer(&self) -> &LineBuffer
pub fn buffer(&self) -> &LineBuffer
Accesses the underlying line buffer.
Sourcepub fn history(&self) -> &HistoryStack
pub fn history(&self) -> &HistoryStack
Accesses the undo/redo history stack.
Sourcepub fn search(&self) -> &FindReplaceState
pub fn search(&self) -> &FindReplaceState
Accesses the active Find & Replace state.
Sourcepub fn search_mut(&mut self) -> &mut FindReplaceState
pub fn search_mut(&mut self) -> &mut FindReplaceState
Mutably accesses the active Find & Replace state.
Sourcepub fn diagnostics(&self) -> &DiagnosticCollection
pub fn diagnostics(&self) -> &DiagnosticCollection
Accesses the diagnostics collection (live syntax + external LSP diagnostics).
Sourcepub fn set_external_diagnostics(&mut self, diagnostics: Vec<EditorDiagnostic>)
pub fn set_external_diagnostics(&mut self, diagnostics: Vec<EditorDiagnostic>)
Replaces external/LSP diagnostics while preserving live syntax diagnostics.
Sourcepub fn clear_external_diagnostics(&mut self)
pub fn clear_external_diagnostics(&mut self)
Clears external/LSP diagnostics.
Sourcepub fn diagnostic_counts(&self) -> DiagnosticCounts
pub fn diagnostic_counts(&self) -> DiagnosticCounts
Returns diagnostic severity counts for status bars and badges.
Sourcepub fn theme(&self) -> &EditorTheme
pub fn theme(&self) -> &EditorTheme
Accesses the active CSS-variable editor theme.
Sourcepub fn set_theme(&mut self, theme: EditorTheme)
pub fn set_theme(&mut self, theme: EditorTheme)
Updates the active editor theme.
pub fn read_only(&self) -> bool
pub fn set_read_only(&mut self, read_only: bool)
pub fn scroll_top(&self) -> f32
pub fn set_scroll_top(&mut self, scroll_top: f32)
pub fn scroll_left(&self) -> f32
pub fn set_scroll_left(&mut self, scroll_left: f32)
pub fn viewport_height(&self) -> f32
pub fn set_viewport_height(&mut self, height: f32)
pub fn line_height(&self) -> f32
pub fn set_line_height(&mut self, line_height: f32)
pub fn char_width(&self) -> f32
pub fn set_char_width(&mut self, char_width: f32)
pub fn max_scroll_top(&self) -> f32
Sourcepub fn cursors(&self) -> &MultiCursor
pub fn cursors(&self) -> &MultiCursor
Accesses the active cursors.
Sourcepub fn cursors_mut(&mut self) -> &mut MultiCursor
pub fn cursors_mut(&mut self) -> &mut MultiCursor
Accesses the active cursors mutably.
Sourcepub fn ime(&self) -> &ImeComposition
pub fn ime(&self) -> &ImeComposition
Returns the active IME composition state.
Sourcepub fn ime_mut(&mut self) -> &mut ImeComposition
pub fn ime_mut(&mut self) -> &mut ImeComposition
Mutably accesses the IME composition state.
Sourcepub fn set_tab_size(&mut self, size: usize)
pub fn set_tab_size(&mut self, size: usize)
Configures tab size.
Sourcepub fn wrap_column(&self) -> Option<usize>
pub fn wrap_column(&self) -> Option<usize>
Returns the soft-wrap column limit, if enabled.
Sourcepub fn set_wrap_column(&mut self, wrap: Option<usize>)
pub fn set_wrap_column(&mut self, wrap: Option<usize>)
Configures soft-wrap column limit.
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Total number of lines in the buffer.
Sourcepub fn insert_char(&mut self, ch: char)
pub fn insert_char(&mut self, ch: char)
Inserts a character at all active cursors (or handles Enter with auto-indentation).
Sourcepub fn insert_newline(&mut self)
pub fn insert_newline(&mut self)
Inserts a newline with automatic indentation calculated from the syntax engine.
Sourcepub fn insert_text(&mut self, text: &str)
pub fn insert_text(&mut self, text: &str)
Inserts text at all cursor positions atomically in descending document order.
Sourcepub fn delete_backwards(&mut self)
pub fn delete_backwards(&mut self)
Performs backspace deletion at all active cursors atomically in descending document order.
Sourcepub fn delete_forward(&mut self)
pub fn delete_forward(&mut self)
Performs forward Delete key deletion at all active cursors atomically.
Sourcepub fn replace_range(
&mut self,
start: Position,
end: Position,
replacement: &str,
) -> Position
pub fn replace_range( &mut self, start: Position, end: Position, replacement: &str, ) -> Position
Replaces an arbitrary [start, end) range with replacement as a single undoable
transaction and drives an incremental Tree-Sitter / line-state update.
Returns the resulting end Position of replacement.
Sourcepub fn replace_ranges_atomic(
&mut self,
replacements: Vec<(Position, Position, String)>,
)
pub fn replace_ranges_atomic( &mut self, replacements: Vec<(Position, Position, String)>, )
Atomically replaces multiple disjoint (start, end, replacement) ranges in descending
document order as a single undo transaction and a single incremental AST reparse.
Sourcepub fn undo(&mut self)
pub fn undo(&mut self)
Undoes the last recorded transaction with incremental AST synchronization.
Sourcepub fn redo(&mut self)
pub fn redo(&mut self)
Redoes the last undone transaction with incremental AST synchronization.
Sourcepub fn move_right(&mut self, select: bool)
pub fn move_right(&mut self, select: bool)
Moves all active cursors right by 1 character.
Sourcepub fn move_to_line_start(&mut self, select: bool)
pub fn move_to_line_start(&mut self, select: bool)
Moves all active cursors to the start of their respective line.
Sourcepub fn move_to_line_end(&mut self, select: bool)
pub fn move_to_line_end(&mut self, select: bool)
Moves all active cursors to the end of their respective line.
Sourcepub fn select_all(&mut self)
pub fn select_all(&mut self)
Selects all text in the document.
Sourcepub fn ensure_folds_cached(&mut self) -> &[FoldRange]
pub fn ensure_folds_cached(&mut self) -> &[FoldRange]
Ensures structural fold ranges are computed and cached for the current buffer state.
Sourcepub fn fold_ranges(&self) -> Vec<FoldRange>
pub fn fold_ranges(&self) -> Vec<FoldRange>
Returns all structural fold ranges for the current document (using cache when valid).
Sourcepub fn toggle_fold(&mut self, line: usize)
pub fn toggle_fold(&mut self, line: usize)
Toggles code folding on the specified line.
Sourcepub fn toggle_fold_at(&mut self, line: usize) -> bool
pub fn toggle_fold_at(&mut self, line: usize) -> bool
Toggles folding at line only if line starts a foldable range; returns true if toggled.
Sourcepub fn unfold_all(&mut self)
pub fn unfold_all(&mut self)
Expands all folded regions in the document.
If line is currently folded, returns the number of hidden lines beneath it.
Sourcepub fn visible_logical_lines(&self) -> Vec<usize>
pub fn visible_logical_lines(&self) -> Vec<usize>
Returns the ordered list of visible 0-indexed logical line numbers after skipping lines concealed inside collapsed fold regions.
Sourcepub fn logical_to_display_row(&self, logical_line: usize) -> Option<usize>
pub fn logical_to_display_row(&self, logical_line: usize) -> Option<usize>
Maps a 0-indexed logical line number to its visible display row index (or None if hidden inside a fold).
Sourcepub fn display_row_to_logical(&self, display_row: usize) -> Option<usize>
pub fn display_row_to_logical(&self, display_row: usize) -> Option<usize>
Maps a visible display row index back to its 0-indexed logical line number.
pub fn open_find(&mut self)
pub fn open_replace(&mut self)
pub fn close_find(&mut self)
pub fn set_find_query(&mut self, query: impl Into<String>)
pub fn set_replace_text(&mut self, replacement: impl Into<String>)
pub fn find_next(&mut self) -> Option<SearchMatch>
pub fn find_prev(&mut self) -> Option<SearchMatch>
pub fn replace_current(&mut self) -> bool
pub fn replace_all(&mut self) -> usize
Sourcepub fn toggle_line_comment(&mut self)
pub fn toggle_line_comment(&mut self)
Toggles single-line comments (// or #) across all lines touched by active selections.
Sourcepub fn indent_selection(&mut self)
pub fn indent_selection(&mut self)
Indents selected lines by tab_size spaces (or inserts spaces at collapsed carets).
Sourcepub fn outdent_selection(&mut self)
pub fn outdent_selection(&mut self)
Outdents selected lines by removing up to tab_size leading spaces (or one leading \t).
Sourcepub fn move_word_left(&mut self, select: bool)
pub fn move_word_left(&mut self, select: bool)
Moves all cursors left by one word boundary.
Sourcepub fn move_word_right(&mut self, select: bool)
pub fn move_word_right(&mut self, select: bool)
Moves all cursors right by one word boundary.
Sourcepub fn select_word_at(&mut self, pos: Position)
pub fn select_word_at(&mut self, pos: Position)
Selects the identifier/word surrounding pos (used on double-click).
Sourcepub fn select_line(&mut self, line: usize)
pub fn select_line(&mut self, line: usize)
Selects the entire logical line (used on triple-click).
Sourcepub fn scroll_to_line(&mut self, logical_line: usize)
pub fn scroll_to_line(&mut self, logical_line: usize)
Scrolls so that logical_line is positioned near the top of the viewport.
Sourcepub fn ensure_line_visible(&mut self, logical_line: usize)
pub fn ensure_line_visible(&mut self, logical_line: usize)
Adjusts scroll_top minimally so logical_line sits inside the visible viewport.
Sourcepub fn ensure_cursor_visible(&mut self)
pub fn ensure_cursor_visible(&mut self)
Scrolls minimally to keep the primary caret visible.
Sourcepub fn position_from_point(
&self,
rel_x: f32,
rel_y: f32,
gutter_width: f32,
) -> Position
pub fn position_from_point( &self, rel_x: f32, rel_y: f32, gutter_width: f32, ) -> Position
Maps an editor-local pointer (rel_x, rel_y) to a document Position.
Sourcepub fn handle_pointer_down(
&mut self,
rel_x: f32,
rel_y: f32,
detail: i32,
alt_key: bool,
shift_key: bool,
gutter_width: f32,
)
pub fn handle_pointer_down( &mut self, rel_x: f32, rel_y: f32, detail: i32, alt_key: bool, shift_key: bool, gutter_width: f32, )
Handles pointer press inside the code viewport (click, Shift+click, Alt+click multi-cursor, double-click word selection, triple-click line selection).
Sourcepub fn handle_pointer_drag(&mut self, rel_x: f32, rel_y: f32, gutter_width: f32)
pub fn handle_pointer_drag(&mut self, rel_x: f32, rel_y: f32, gutter_width: f32)
Extends the active primary selection while dragging the pointer.
Sourcepub fn handle_pointer_up(&mut self)
pub fn handle_pointer_up(&mut self)
Ends a pointer drag gesture.
Sourcepub fn handle_wheel(&mut self, delta_y: f32)
pub fn handle_wheel(&mut self, delta_y: f32)
Handles wheel scrolling over the editor viewport.
Sourcepub fn handle_minimap_pointer(
&mut self,
pointer_y: f32,
minimap_height: f32,
config: &MinimapConfig,
)
pub fn handle_minimap_pointer( &mut self, pointer_y: f32, minimap_height: f32, config: &MinimapConfig, )
Handles click or drag inside the Canvas2D minimap to jump/scrub scroll_top.
Sourcepub fn copy_selection(&self) -> Option<String>
pub fn copy_selection(&self) -> Option<String>
Copies the active selection(s) to Strata’s unified clipboard and returns the copied string. When all cursors are collapsed, copies the primary cursor’s full logical line (Monaco/VS Code parity).
Sourcepub fn cut_selection(&mut self) -> Option<String>
pub fn cut_selection(&mut self) -> Option<String>
Cuts the active selection(s) (or primary logical line when collapsed) to Strata’s unified clipboard.
Sourcepub fn paste_text(&mut self, text: &str) -> bool
pub fn paste_text(&mut self, text: &str) -> bool
Pastes UTF-8 text (normalizing CRLF/CR line endings) at all active cursors.
Sourcepub fn handle_input_event(&mut self, e: &Event) -> bool
pub fn handle_input_event(&mut self, e: &Event) -> bool
Handles a W3C DOM EventType::Input event (e.g. atomic multi-character ImeCommit).
Sourcepub fn handle_key_event(&mut self, e: &Event) -> bool
pub fn handle_key_event(&mut self, e: &Event) -> bool
Handles a W3C-compatible Strata Event keydown with full Monaco keybindings.
Returns true if the event was handled and mutated editor state.
Sourcepub fn render(&self) -> NodeBlueprint
pub fn render(&self) -> NodeBlueprint
Renders a complete code editor view blueprint with default styling.
Sourcepub fn render_blueprint(&self, class_style: &str) -> NodeBlueprint
pub fn render_blueprint(&self, class_style: &str) -> NodeBlueprint
Renders a complete code editor view blueprint with line numbering gutter and syntax tokens.
Sourcepub fn token_type_class(token_type: TokenType) -> &'static str
pub fn token_type_class(token_type: TokenType) -> &'static str
Maps a semantic TokenType to a Tailwind utility class string.
Sourcepub fn render_virtualized(
&self,
scroll_top: f32,
viewport_height: f32,
line_height: f32,
class_style: &str,
) -> NodeBlueprint
pub fn render_virtualized( &self, scroll_top: f32, viewport_height: f32, line_height: f32, class_style: &str, ) -> NodeBlueprint
Renders a virtualized viewport slice of the code editor.
Only the lines currently visible in the scroll viewport (plus an overscan margin) are laid out and styled into DOM blueprint nodes. Spacer containers at the top and bottom maintain the exact natural scroll height of the entire document.