Skip to main content

EditorState

Struct EditorState 

Source
pub struct EditorState {
Show 25 fields pub buffer: Buffer, pub highlighter: HighlightEngine, pub indent_calculator: RefCell<IndentCalculator>, pub overlays: OverlayManager, pub marker_list: MarkerList, pub virtual_texts: VirtualTextManager, pub conceals: ConcealManager, pub soft_breaks: SoftBreakManager, pub popups: PopupManager, pub margins: MarginManager, pub primary_cursor_line_number: LineNumber, pub mode: String, pub text_properties: TextPropertyManager, pub show_cursors: bool, pub editing_disabled: bool, pub buffer_settings: BufferSettings, pub reference_highlighter: ReferenceHighlighter, pub is_composite_buffer: bool, pub debug_highlight_mode: bool, pub reference_highlight_overlay: ReferenceHighlightOverlay, pub bracket_highlight_overlay: BracketHighlightOverlay, pub semantic_tokens: Option<SemanticTokenStore>, pub folding_ranges: Vec<FoldingRange>, pub language: String, pub display_name: String,
}
Expand description

The complete editor state - everything needed to represent the current editing session

NOTE: Viewport is NOT stored here - it lives in SplitViewState. This is because viewport is view-specific (each split can view the same buffer at different scroll positions), while EditorState represents the buffer content.

Fields§

§buffer: Buffer

The text buffer

§highlighter: HighlightEngine

Syntax highlighter (tree-sitter or TextMate based on language)

§indent_calculator: RefCell<IndentCalculator>

Auto-indent calculator for smart indentation (RefCell for interior mutability)

§overlays: OverlayManager

Overlays for visual decorations (underlines, highlights, etc.)

§marker_list: MarkerList

Marker list for content-anchored overlay positions

§virtual_texts: VirtualTextManager

Virtual text manager for inline hints (type hints, parameter hints, etc.)

§conceals: ConcealManager

Conceal ranges for hiding/replacing byte ranges during rendering

§soft_breaks: SoftBreakManager

Soft break points for marker-based line wrapping during rendering

§popups: PopupManager

Popups for floating windows (completion, documentation, etc.)

§margins: MarginManager

Margins for line numbers, annotations, gutter symbols, etc.)

§primary_cursor_line_number: LineNumber

Cached line number for primary cursor (0-indexed) Maintained incrementally to avoid O(n) scanning on every render

§mode: String

Current mode (for modal editing, if implemented)

§text_properties: TextPropertyManager

Text properties for virtual buffers (embedded metadata in text ranges) Used by virtual buffers to store location info, severity, etc.

§show_cursors: bool

Whether to show cursors in this buffer (default true) Can be set to false for virtual buffers like diagnostics panels

§editing_disabled: bool

Whether editing is disabled for this buffer (default false) When true, typing, deletion, cut/paste, undo/redo are blocked but navigation, selection, and copy are still allowed

§buffer_settings: BufferSettings

Per-buffer user settings (tab size, indentation style, etc.) These settings are preserved across file reloads (auto-revert)

§reference_highlighter: ReferenceHighlighter

Semantic highlighter for word occurrence highlighting

§is_composite_buffer: bool

Whether this buffer is a composite view (e.g., side-by-side diff)

§debug_highlight_mode: bool

Debug mode: reveal highlight/overlay spans (WordPerfect-style)

§reference_highlight_overlay: ReferenceHighlightOverlay

Debounced semantic highlight cache

§bracket_highlight_overlay: BracketHighlightOverlay

Bracket matching highlight overlay

§semantic_tokens: Option<SemanticTokenStore>

Cached LSP semantic tokens (converted to buffer byte ranges)

§folding_ranges: Vec<FoldingRange>

Last-known LSP folding ranges for this buffer

§language: String

The detected language ID for this buffer (e.g., “rust”, “csharp”, “text”). Used for LSP config lookup and internal identification.

§display_name: String

Human-readable language display name (e.g., “Rust”, “C#”, “Plain Text”). Shown in the status bar and Set Language prompt.

Implementations§

Source§

impl EditorState

Source

pub fn apply_language(&mut self, detected: DetectedLanguage)

Create a new editor state with an empty buffer

Note: width/height parameters are kept for backward compatibility but are no longer used - viewport is now owned by SplitViewState. Apply a detected language to this state. This is the single mutation point for changing the language of a buffer after creation.

Source

pub fn new( _width: u16, _height: u16, large_file_threshold: usize, fs: Arc<dyn FileSystem + Send + Sync>, ) -> Self

Source

pub fn new_with_path( large_file_threshold: usize, fs: Arc<dyn FileSystem + Send + Sync>, path: PathBuf, ) -> Self

Create a new editor state with an empty buffer associated with a file path. Used for files that don’t exist yet — the path is set so saving will create the file.

Source

pub fn set_language_from_name(&mut self, name: &str, registry: &GrammarRegistry)

Set the syntax highlighting language based on a virtual buffer name. Handles names like *OLD:test.ts* or *OURS*.c by stripping markers and detecting language from the cleaned filename.

Source

pub fn from_file( path: &Path, _width: u16, _height: u16, large_file_threshold: usize, registry: &GrammarRegistry, fs: Arc<dyn FileSystem + Send + Sync>, ) -> Result<Self>

Create an editor state from a file

Note: width/height parameters are kept for backward compatibility but are no longer used - viewport is now owned by SplitViewState.

Source

pub fn from_file_with_languages( path: &Path, _width: u16, _height: u16, large_file_threshold: usize, registry: &GrammarRegistry, languages: &HashMap<String, LanguageConfig>, fs: Arc<dyn FileSystem + Send + Sync>, ) -> Result<Self>

Create an editor state from a file with language configuration.

This version uses the provided languages configuration for syntax detection, allowing user-configured filename patterns to be respected for highlighting.

Note: width/height parameters are kept for backward compatibility but are no longer used - viewport is now owned by SplitViewState.

Source

pub fn from_buffer_with_language( buffer: Buffer, detected: DetectedLanguage, ) -> Self

Create an editor state from a buffer and a pre-built DetectedLanguage.

This is useful when you have already loaded a buffer with a specific encoding and want to create an EditorState from it.

Source

pub fn apply(&mut self, cursors: &mut Cursors, event: &Event)

Apply an event to the state - THE ONLY WAY TO MODIFY STATE This is the heart of the event-driven architecture

Source

pub fn capture_displaced_markers( &self, range: &Range<usize>, ) -> Vec<(u64, usize)>

Capture positions of markers strictly inside a deleted range. Call this BEFORE applying the delete. Returns encoded displaced markers.

Source

pub fn capture_displaced_markers_bulk( &self, edits: &[(usize, usize, String)], ) -> Vec<(u64, usize)>

Capture displaced markers for multiple delete ranges (BulkEdit).

Source

pub fn restore_displaced_markers(&mut self, displaced: &[(u64, usize)])

Restore displaced markers to their exact original positions.

Source

pub fn apply_many(&mut self, cursors: &mut Cursors, events: &[Event])

Apply multiple events in sequence

Source

pub fn on_focus_lost(&mut self)

Called when this buffer loses focus (e.g., switching to another buffer, opening a prompt, focusing file explorer, etc.) Dismisses transient popups like Hover and Signature Help.

Source§

impl EditorState

Source

pub fn prepare_for_render(&mut self, top_byte: usize, height: u16) -> Result<()>

Prepare viewport for rendering (called before frame render)

This pre-loads all data that will be needed for rendering the current viewport, ensuring that subsequent read-only access during rendering will succeed.

Takes viewport parameters since viewport is now owned by SplitViewState.

Source

pub fn get_text_range(&mut self, start: usize, end: usize) -> String

Get text in a range, driving lazy loading transparently

This is a convenience wrapper around DocumentModel::get_range that:

  • Drives lazy loading automatically (never fails due to unloaded data)
  • Uses byte offsets directly
  • Returns String (not Result) - errors are logged internally
  • Returns empty string for invalid ranges

This is the preferred API for getting text ranges. The caller never needs to worry about lazy loading or buffer preparation.

§Example
let text = state.get_text_range(0, 100);
Source

pub fn get_line_at_offset(&mut self, offset: usize) -> Option<(usize, String)>

Get the content of a line by its byte offset

Returns the line containing the given offset, along with its start position. This uses DocumentModel’s viewport functionality for consistent behavior.

§Returns

Some((line_start_offset, line_content)) if successful, None if offset is invalid

Source

pub fn get_text_to_end_of_line(&mut self, cursor_pos: usize) -> Result<String>

Get text from current cursor position to end of line

This is a common pattern in editing operations. Uses DocumentModel for consistent behavior across file sizes.

Source

pub fn set_semantic_tokens(&mut self, store: SemanticTokenStore)

Replace cached semantic tokens with a new store.

Source

pub fn clear_semantic_tokens(&mut self)

Clear cached semantic tokens (e.g., when tokens are invalidated).

Source

pub fn semantic_tokens_result_id(&self) -> Option<&str>

Get the server-provided semantic token result_id if available.

Trait Implementations§

Source§

impl DocumentModel for EditorState

Implement DocumentModel trait for EditorState

This provides a clean abstraction layer between rendering/editing operations and the underlying text buffer implementation.

Source§

fn capabilities(&self) -> DocumentCapabilities

Get document capabilities
Source§

fn get_viewport_content( &mut self, start_pos: DocumentPosition, max_lines: usize, ) -> Result<ViewportContent>

Get content at a viewport (the core rendering primitive) Read more
Source§

fn position_to_offset(&self, pos: DocumentPosition) -> Result<usize>

Convert position to byte offset (always works)
Source§

fn offset_to_position(&self, offset: usize) -> DocumentPosition

Convert byte offset to a position Read more
Source§

fn get_range( &mut self, start: DocumentPosition, end: DocumentPosition, ) -> Result<String>

Get a range of text by positions May trigger lazy loading for large files
Source§

fn get_line_content(&mut self, line_number: usize) -> Option<String>

Get a single line if line indexing is available Read more
Source§

fn get_chunk_at_offset( &mut self, offset: usize, size: usize, ) -> Result<(usize, String)>

Get text around a byte offset (for operations that don’t need exact lines) Read more
Source§

fn insert(&mut self, pos: DocumentPosition, text: &str) -> Result<usize>

Insert text at a position Read more
Source§

fn delete( &mut self, start: DocumentPosition, end: DocumentPosition, ) -> Result<()>

Delete a range
Source§

fn replace( &mut self, start: DocumentPosition, end: DocumentPosition, text: &str, ) -> Result<()>

Replace a range
Source§

fn find_matches( &mut self, pattern: &str, search_range: Option<(DocumentPosition, DocumentPosition)>, ) -> Result<Vec<usize>>

Find all matches of a pattern in a range Read more
Source§

fn has_line_index(&self) -> bool

Check if line indexing is available

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'a, T> FromIn<'a, T> for T

Source§

fn from_in(t: T, _: &'a Allocator) -> T

Converts to this type from the input type within the given allocator.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<'a, T, U> IntoIn<'a, U> for T
where U: FromIn<'a, T>,

Source§

fn into_in(self, allocator: &'a Allocator) -> U

Converts this type into the (usually inferred) input type within the given allocator.
Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ParallelSend for T