pub struct EditorCore {
pub piece_table: PieceTable,
pub line_index: LineIndex,
pub layout_engine: LayoutEngine,
pub interval_tree: IntervalTree,
pub style_layers: BTreeMap<StyleLayerId, IntervalTree>,
pub folding_manager: FoldingManager,
pub cursor_position: Position,
pub selection: Option<Selection>,
pub secondary_selections: Vec<Selection>,
pub viewport_width: usize,
}Expand description
Editor Core state
EditorCore aggregates all underlying editor components, including:
- PieceTable: Efficient text storage and modification
- LineIndex: Rope-based line index, supporting fast line access
- LayoutEngine: Soft wrapping and text layout calculation
- IntervalTree: Style interval management
- FoldingManager: Code folding management
- Cursor & Selection: Cursor and selection state
§Example
use editor_core::EditorCore;
let mut core = EditorCore::new("Hello\nWorld", 80);
assert_eq!(core.line_count(), 2);
assert_eq!(core.get_text(), "Hello\nWorld");Fields§
§piece_table: PieceTablePiece Table storage layer
line_index: LineIndexLine index
layout_engine: LayoutEngineLayout engine
interval_tree: IntervalTreeInterval tree (style management)
style_layers: BTreeMap<StyleLayerId, IntervalTree>Layered styles (for semantic highlighting/simple syntax highlighting, etc.)
folding_manager: FoldingManagerFolding manager
cursor_position: PositionCurrent cursor position
selection: Option<Selection>Current selection range
secondary_selections: Vec<Selection>Secondary selections/cursors (multi-cursor). Each Selection can be empty (start==end), representing a caret.
viewport_width: usizeViewport width
Implementations§
Source§impl EditorCore
impl EditorCore
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Get total line count
Sourcepub fn char_count(&self) -> usize
pub fn char_count(&self) -> usize
Get total character count
Sourcepub fn cursor_position(&self) -> Position
pub fn cursor_position(&self) -> Position
Get cursor position
Sourcepub fn secondary_selections(&self) -> &[Selection]
pub fn secondary_selections(&self) -> &[Selection]
Get secondary selections/cursors (multi-cursor)
Sourcepub fn get_headless_grid_styled(
&self,
start_visual_row: usize,
count: usize,
) -> HeadlessGrid
pub fn get_headless_grid_styled( &self, start_visual_row: usize, count: usize, ) -> HeadlessGrid
Get styled headless grid snapshot (by visual line).
- Supportsoft wrapping (based
layout_engine) Cell.styleswillinterval_tree+style_layersmerged from- Supportcode folding (based
folding_manager)
Note: This API is not responsible for mapping StyleId to specific colors.
Sourcepub fn visual_line_count(&self) -> usize
pub fn visual_line_count(&self) -> usize
Get total visual line count (considering soft wrapping + folding).
Sourcepub fn visual_to_logical_line(&self, visual_line: usize) -> (usize, usize)
pub fn visual_to_logical_line(&self, visual_line: usize) -> (usize, usize)
Map visual line number back to (logical_line, visual_in_logical), considering folding.
Sourcepub fn logical_position_to_visual(
&self,
logical_line: usize,
column: usize,
) -> Option<(usize, usize)>
pub fn logical_position_to_visual( &self, logical_line: usize, column: usize, ) -> Option<(usize, usize)>
Convert logical coordinates (line, column) to visual coordinates (visual line number, in-line x cell offset), considering folding.
Sourcepub fn logical_position_to_visual_allow_virtual(
&self,
logical_line: usize,
column: usize,
) -> Option<(usize, usize)>
pub fn logical_position_to_visual_allow_virtual( &self, logical_line: usize, column: usize, ) -> Option<(usize, usize)>
Convert logical coordinates (line, column) to visual coordinates (visual line number, in-line x cell offset), considering folding.
Difference from logical_position_to_visual is that it allows column
to exceed the line end: the exceeding part is treated as ' ' (width=1) virtual spaces, suitable for rectangular selection / column editing.