Skip to main content

Module state

Module state 

Source
Expand description

Editor State Interface

Provides a complete state query interface for the editor, used for frontend rendering and state synchronization.

§Overview

The state interface layer exposes the editor’s internal state to the frontend in a structured, immutable manner. It supports:

  • State Queries: Retrieve document, cursor, viewport, and other state information
  • Version Tracking: Track state changes through version numbers
  • Change Notifications: Subscribe to state change events
  • Viewport Management: Obtain rendering data for visible regions

§Example

use editor_core::{EditorStateManager, StateChangeType};

let mut manager = EditorStateManager::new("Hello, World!", 80);

// Query document state
let doc_state = manager.get_document_state();
println!("Line count: {}", doc_state.line_count);

// Subscribe to state changes
manager.subscribe(|change| {
    println!("State changed: {:?}", change.change_type);
});

// Modify document and mark changes
manager.editor_mut().piece_table.insert(0, "New: ");
manager.mark_modified(StateChangeType::DocumentModified);

Structs§

CursorState
Cursor state
DecorationsState
Decorations state
DiagnosticsState
Diagnostics state
DocumentState
Document state
EditorState
Complete editor state snapshot
EditorStateManager
Editor state manager
FoldingState
Folding state
StateChange
State change record
StyleState
Style state
UndoRedoState
Undo/redo stack state
ViewportState
Viewport state

Enums§

StateChangeType
State change type

Type Aliases§

StateChangeCallback
State change callback function type