Skip to main content

CodeEditor

Struct CodeEditor 

Source
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

Source

pub fn new(content: &str, language: Language) -> Self

Constructs a new code editor with initial source code and language syntax.

Source

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.

Source

pub fn highlighter(&self) -> &SyntaxHighlighter

Accesses the active syntax highlighter.

Source

pub fn highlighter_mut(&mut self) -> &mut SyntaxHighlighter

Accesses the active syntax highlighter mutably.

Source

pub fn language(&self) -> Language

Returns the active syntax language.

Source

pub fn set_language(&mut self, language: Language)

Changes the syntax language and re-parses the AST directly from the rope buffer.

Source

pub fn reparse(&mut self)

Re-parses the document incrementally with the active Tree-Sitter grammar via zero-copy rope slices.

Source

pub fn buffer(&self) -> &LineBuffer

Accesses the underlying line buffer.

Source

pub fn history(&self) -> &HistoryStack

Accesses the undo/redo history stack.

Source

pub fn search(&self) -> &FindReplaceState

Accesses the active Find & Replace state.

Source

pub fn search_mut(&mut self) -> &mut FindReplaceState

Mutably accesses the active Find & Replace state.

Source

pub fn diagnostics(&self) -> &DiagnosticCollection

Accesses the diagnostics collection (live syntax + external LSP diagnostics).

Source

pub fn set_external_diagnostics(&mut self, diagnostics: Vec<EditorDiagnostic>)

Replaces external/LSP diagnostics while preserving live syntax diagnostics.

Source

pub fn clear_external_diagnostics(&mut self)

Clears external/LSP diagnostics.

Source

pub fn diagnostic_counts(&self) -> DiagnosticCounts

Returns diagnostic severity counts for status bars and badges.

Source

pub fn theme(&self) -> &EditorTheme

Accesses the active CSS-variable editor theme.

Source

pub fn set_theme(&mut self, theme: EditorTheme)

Updates the active editor theme.

Source

pub fn read_only(&self) -> bool

Source

pub fn set_read_only(&mut self, read_only: bool)

Source

pub fn scroll_top(&self) -> f32

Source

pub fn set_scroll_top(&mut self, scroll_top: f32)

Source

pub fn scroll_left(&self) -> f32

Source

pub fn set_scroll_left(&mut self, scroll_left: f32)

Source

pub fn viewport_height(&self) -> f32

Source

pub fn set_viewport_height(&mut self, height: f32)

Source

pub fn line_height(&self) -> f32

Source

pub fn set_line_height(&mut self, line_height: f32)

Source

pub fn char_width(&self) -> f32

Source

pub fn set_char_width(&mut self, char_width: f32)

Source

pub fn max_scroll_top(&self) -> f32

Source

pub fn cursors(&self) -> &MultiCursor

Accesses the active cursors.

Source

pub fn cursors_mut(&mut self) -> &mut MultiCursor

Accesses the active cursors mutably.

Source

pub fn ime(&self) -> &ImeComposition

Returns the active IME composition state.

Source

pub fn ime_mut(&mut self) -> &mut ImeComposition

Mutably accesses the IME composition state.

Source

pub fn tab_size(&self) -> usize

Returns the configured tab size (in spaces).

Source

pub fn set_tab_size(&mut self, size: usize)

Configures tab size.

Source

pub fn wrap_column(&self) -> Option<usize>

Returns the soft-wrap column limit, if enabled.

Source

pub fn set_wrap_column(&mut self, wrap: Option<usize>)

Configures soft-wrap column limit.

Source

pub fn line_count(&self) -> usize

Total number of lines in the buffer.

Source

pub fn text(&self) -> String

Serializes entire buffer content to a String.

Source

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

Replaces entire buffer content and resets history.

Source

pub fn insert_char(&mut self, ch: char)

Inserts a character at all active cursors (or handles Enter with auto-indentation).

Source

pub fn insert_newline(&mut self)

Inserts a newline with automatic indentation calculated from the syntax engine.

Source

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

Inserts text at all cursor positions atomically in descending document order.

Source

pub fn delete_backwards(&mut self)

Performs backspace deletion at all active cursors atomically in descending document order.

Source

pub fn delete_forward(&mut self)

Performs forward Delete key deletion at all active cursors atomically.

Source

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.

Source

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.

Source

pub fn undo(&mut self)

Undoes the last recorded transaction with incremental AST synchronization.

Source

pub fn redo(&mut self)

Redoes the last undone transaction with incremental AST synchronization.

Source

pub fn move_left(&mut self, select: bool)

Moves all active cursors left by 1 character.

Source

pub fn move_right(&mut self, select: bool)

Moves all active cursors right by 1 character.

Source

pub fn move_up(&mut self, select: bool)

Moves all active cursors up by 1 line.

Source

pub fn move_down(&mut self, select: bool)

Moves all active cursors down by 1 line.

Source

pub fn move_to_line_start(&mut self, select: bool)

Moves all active cursors to the start of their respective line.

Source

pub fn move_to_line_end(&mut self, select: bool)

Moves all active cursors to the end of their respective line.

Source

pub fn select_all(&mut self)

Selects all text in the document.

Source

pub fn ensure_folds_cached(&mut self) -> &[FoldRange]

Ensures structural fold ranges are computed and cached for the current buffer state.

Source

pub fn fold_ranges(&self) -> Vec<FoldRange>

Returns all structural fold ranges for the current document (using cache when valid).

Source

pub fn toggle_fold(&mut self, line: usize)

Toggles code folding on the specified line.

Source

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.

Source

pub fn fold_all(&mut self)

Collapses every foldable block in the document.

Source

pub fn unfold_all(&mut self)

Expands all folded regions in the document.

Source

pub fn is_folded(&self, line: usize) -> bool

Checks if the line is currently folded.

Source

pub fn folded_hidden_count(&self, line: usize) -> Option<usize>

If line is currently folded, returns the number of hidden lines beneath it.

Source

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.

Source

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).

Source

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.

Source

pub fn open_find(&mut self)

Source

pub fn open_replace(&mut self)

Source

pub fn close_find(&mut self)

Source

pub fn set_find_query(&mut self, query: impl Into<String>)

Source

pub fn set_replace_text(&mut self, replacement: impl Into<String>)

Source

pub fn find_next(&mut self) -> Option<SearchMatch>

Source

pub fn find_prev(&mut self) -> Option<SearchMatch>

Source

pub fn replace_current(&mut self) -> bool

Source

pub fn replace_all(&mut self) -> usize

Source

pub fn toggle_line_comment(&mut self)

Toggles single-line comments (// or #) across all lines touched by active selections.

Source

pub fn indent_selection(&mut self)

Indents selected lines by tab_size spaces (or inserts spaces at collapsed carets).

Source

pub fn outdent_selection(&mut self)

Outdents selected lines by removing up to tab_size leading spaces (or one leading \t).

Source

pub fn move_word_left(&mut self, select: bool)

Moves all cursors left by one word boundary.

Source

pub fn move_word_right(&mut self, select: bool)

Moves all cursors right by one word boundary.

Source

pub fn page_up(&mut self, select: bool)

Moves cursors up by one viewport page.

Source

pub fn page_down(&mut self, select: bool)

Moves cursors down by one viewport page.

Source

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

Selects the identifier/word surrounding pos (used on double-click).

Source

pub fn select_line(&mut self, line: usize)

Selects the entire logical line (used on triple-click).

Source

pub fn scroll_by(&mut self, delta_y: f32)

Scrolls the viewport vertically by delta_y pixels.

Source

pub fn scroll_to_line(&mut self, logical_line: usize)

Scrolls so that logical_line is positioned near the top of the viewport.

Source

pub fn ensure_line_visible(&mut self, logical_line: usize)

Adjusts scroll_top minimally so logical_line sits inside the visible viewport.

Source

pub fn ensure_cursor_visible(&mut self)

Scrolls minimally to keep the primary caret visible.

Source

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.

Source

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).

Source

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.

Source

pub fn handle_pointer_up(&mut self)

Ends a pointer drag gesture.

Source

pub fn handle_wheel(&mut self, delta_y: f32)

Handles wheel scrolling over the editor viewport.

Source

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.

Source

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).

Source

pub fn cut_selection(&mut self) -> Option<String>

Cuts the active selection(s) (or primary logical line when collapsed) to Strata’s unified clipboard.

Source

pub fn paste_text(&mut self, text: &str) -> bool

Pastes UTF-8 text (normalizing CRLF/CR line endings) at all active cursors.

Source

pub fn handle_input_event(&mut self, e: &Event) -> bool

Handles a W3C DOM EventType::Input event (e.g. atomic multi-character ImeCommit).

Source

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.

Source

pub fn render(&self) -> NodeBlueprint

Renders a complete code editor view blueprint with default styling.

Source

pub fn render_blueprint(&self, class_style: &str) -> NodeBlueprint

Renders a complete code editor view blueprint with line numbering gutter and syntax tokens.

Source

pub fn token_type_class(token_type: TokenType) -> &'static str

Maps a semantic TokenType to a Tailwind utility class string.

Source

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.

Trait Implementations§

Source§

impl Clone for CodeEditor

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CodeEditor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> IntoInitialState<T> for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,