pub struct EditorState {Show 29 fields
pub buffer: Buffer,
pub cursors: Cursors,
pub highlighter: HighlightEngine,
pub indent_calculator: RefCell<IndentCalculator>,
pub overlays: OverlayManager,
pub marker_list: MarkerList,
pub virtual_texts: VirtualTextManager,
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 is_composite_buffer: bool,
pub show_whitespace_tabs: bool,
pub use_tabs: bool,
pub tab_size: usize,
pub reference_highlighter: ReferenceHighlighter,
pub view_mode: ViewMode,
pub debug_highlight_mode: bool,
pub compose_width: Option<u16>,
pub compose_prev_line_numbers: Option<bool>,
pub compose_column_guides: Option<Vec<u16>>,
pub view_transform: Option<ViewTransformPayload>,
pub reference_highlight_overlay: ReferenceHighlightOverlay,
pub bracket_highlight_overlay: BracketHighlightOverlay,
pub semantic_tokens: Option<SemanticTokenStore>,
pub language: 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: BufferThe text buffer
cursors: CursorsAll cursors
highlighter: HighlightEngineSyntax highlighter (tree-sitter or TextMate based on language)
indent_calculator: RefCell<IndentCalculator>Auto-indent calculator for smart indentation (RefCell for interior mutability)
overlays: OverlayManagerOverlays for visual decorations (underlines, highlights, etc.)
marker_list: MarkerListMarker list for content-anchored overlay positions
virtual_texts: VirtualTextManagerVirtual text manager for inline hints (type hints, parameter hints, etc.)
popups: PopupManagerPopups for floating windows (completion, documentation, etc.)
margins: MarginManagerMargins for line numbers, annotations, gutter symbols, etc.)
primary_cursor_line_number: LineNumberCached line number for primary cursor (0-indexed) Maintained incrementally to avoid O(n) scanning on every render
mode: StringCurrent mode (for modal editing, if implemented)
text_properties: TextPropertyManagerText properties for virtual buffers (embedded metadata in text ranges) Used by virtual buffers to store location info, severity, etc.
show_cursors: boolWhether to show cursors in this buffer (default true) Can be set to false for virtual buffers like diagnostics panels
editing_disabled: boolWhether 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
is_composite_buffer: boolWhether this buffer is a composite buffer (multi-pane view) When true, the buffer content is rendered by the composite renderer instead of the normal buffer rendering path
show_whitespace_tabs: boolWhether to show whitespace tab indicators (→) for this buffer Set based on language config; defaults to true
use_tabs: boolWhether pressing Tab should insert a tab character instead of spaces. Set based on language config; defaults to false (insert spaces).
tab_size: usizeTab size (number of spaces per tab character) for rendering. Used for visual display of tab characters and indent calculations.
reference_highlighter: ReferenceHighlighterSemantic highlighter for word occurrence highlighting
view_mode: ViewModeView mode for this buffer (Source or Compose)
debug_highlight_mode: boolDebug mode: show highlight/overlay byte ranges When enabled, each character shows its byte position and highlight info
compose_width: Option<u16>Optional compose width for centered rendering
compose_prev_line_numbers: Option<bool>Previously configured line number visibility (to restore after Compose)
compose_column_guides: Option<Vec<u16>>Optional column guides (e.g., for tables) supplied by layout hints
view_transform: Option<ViewTransformPayload>Optional transformed view payload for current viewport (tokens + map)
reference_highlight_overlay: ReferenceHighlightOverlayDebounced semantic highlight cache
bracket_highlight_overlay: BracketHighlightOverlayBracket matching highlight overlay
semantic_tokens: Option<SemanticTokenStore>Cached LSP semantic tokens (converted to buffer byte ranges)
language: StringThe detected language for this buffer (e.g., “rust”, “python”, “text”)
Implementations§
Source§impl EditorState
impl EditorState
Sourcepub fn new(
_width: u16,
_height: u16,
large_file_threshold: usize,
fs: Arc<dyn FileSystem + Send + Sync>,
) -> Self
pub fn new( _width: u16, _height: u16, large_file_threshold: usize, fs: Arc<dyn FileSystem + Send + Sync>, ) -> Self
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.
Sourcepub fn set_language_from_name(&mut self, name: &str, registry: &GrammarRegistry)
pub fn set_language_from_name(&mut self, name: &str, registry: &GrammarRegistry)
Set the syntax highlighting language based on a filename or extension This allows virtual buffers to get highlighting even without a real file path
Sourcepub fn from_file(
path: &Path,
_width: u16,
_height: u16,
large_file_threshold: usize,
registry: &GrammarRegistry,
fs: Arc<dyn FileSystem + Send + Sync>,
) -> Result<Self>
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.
Sourcepub 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>
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.
Sourcepub fn apply(&mut self, event: &Event)
pub fn apply(&mut self, event: &Event)
Apply an event to the state - THE ONLY WAY TO MODIFY STATE This is the heart of the event-driven architecture
Sourcepub fn apply_many(&mut self, events: &[Event])
pub fn apply_many(&mut self, events: &[Event])
Apply multiple events in sequence
Sourcepub fn primary_cursor(&self) -> &Cursor
pub fn primary_cursor(&self) -> &Cursor
Get the primary cursor
Sourcepub fn primary_cursor_mut(&mut self) -> &mut Cursor
pub fn primary_cursor_mut(&mut self) -> &mut Cursor
Get the primary cursor mutably (for reading state only, not for modification!)
Sourcepub fn on_focus_lost(&mut self)
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
impl EditorState
Sourcepub fn prepare_for_render(&mut self, top_byte: usize, height: u16) -> Result<()>
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.
Sourcepub fn get_text_range(&mut self, start: usize, end: usize) -> String
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);Sourcepub fn get_line_at_offset(&mut self, offset: usize) -> Option<(usize, String)>
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
Sourcepub fn get_text_to_end_of_line(&mut self, cursor_pos: usize) -> Result<String>
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.
Sourcepub fn set_semantic_tokens(&mut self, store: SemanticTokenStore)
pub fn set_semantic_tokens(&mut self, store: SemanticTokenStore)
Replace cached semantic tokens with a new store.
Sourcepub fn clear_semantic_tokens(&mut self)
pub fn clear_semantic_tokens(&mut self)
Clear cached semantic tokens (e.g., when tokens are invalidated).
Sourcepub fn semantic_tokens_result_id(&self) -> Option<&str>
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
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
fn capabilities(&self) -> DocumentCapabilities
Source§fn get_viewport_content(
&mut self,
start_pos: DocumentPosition,
max_lines: usize,
) -> Result<ViewportContent>
fn get_viewport_content( &mut self, start_pos: DocumentPosition, max_lines: usize, ) -> Result<ViewportContent>
Source§fn position_to_offset(&self, pos: DocumentPosition) -> Result<usize>
fn position_to_offset(&self, pos: DocumentPosition) -> Result<usize>
Source§fn offset_to_position(&self, offset: usize) -> DocumentPosition
fn offset_to_position(&self, offset: usize) -> DocumentPosition
Source§fn get_range(
&mut self,
start: DocumentPosition,
end: DocumentPosition,
) -> Result<String>
fn get_range( &mut self, start: DocumentPosition, end: DocumentPosition, ) -> Result<String>
Source§fn get_line_content(&mut self, line_number: usize) -> Option<String>
fn get_line_content(&mut self, line_number: usize) -> Option<String>
Source§fn get_chunk_at_offset(
&mut self,
offset: usize,
size: usize,
) -> Result<(usize, String)>
fn get_chunk_at_offset( &mut self, offset: usize, size: usize, ) -> Result<(usize, String)>
Source§fn insert(&mut self, pos: DocumentPosition, text: &str) -> Result<usize>
fn insert(&mut self, pos: DocumentPosition, text: &str) -> Result<usize>
Source§fn delete(
&mut self,
start: DocumentPosition,
end: DocumentPosition,
) -> Result<()>
fn delete( &mut self, start: DocumentPosition, end: DocumentPosition, ) -> Result<()>
Source§fn replace(
&mut self,
start: DocumentPosition,
end: DocumentPosition,
text: &str,
) -> Result<()>
fn replace( &mut self, start: DocumentPosition, end: DocumentPosition, text: &str, ) -> Result<()>
Source§fn find_matches(
&mut self,
pattern: &str,
search_range: Option<(DocumentPosition, DocumentPosition)>,
) -> Result<Vec<usize>>
fn find_matches( &mut self, pattern: &str, search_range: Option<(DocumentPosition, DocumentPosition)>, ) -> Result<Vec<usize>>
Source§fn has_line_index(&self) -> bool
fn has_line_index(&self) -> bool
Auto Trait Implementations§
impl !Freeze for EditorState
impl !RefUnwindSafe for EditorState
impl !Send for EditorState
impl !Sync for EditorState
impl Unpin for EditorState
impl !UnwindSafe for EditorState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more