Skip to main content

EditorCore

Struct EditorCore 

Source
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: PieceTable

Piece Table storage layer

§line_index: LineIndex

Line index

§layout_engine: LayoutEngine

Layout engine

§interval_tree: IntervalTree

Interval tree (style management)

§style_layers: BTreeMap<StyleLayerId, IntervalTree>

Layered styles (for semantic highlighting/simple syntax highlighting, etc.)

§folding_manager: FoldingManager

Folding manager

§cursor_position: Position

Current 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: usize

Viewport width

Implementations§

Source§

impl EditorCore

Source

pub fn new(text: &str, viewport_width: usize) -> Self

Create a new Editor Core

Source

pub fn empty(viewport_width: usize) -> Self

Create an empty Editor Core

Source

pub fn get_text(&self) -> String

Get text content

Source

pub fn line_count(&self) -> usize

Get total line count

Source

pub fn char_count(&self) -> usize

Get total character count

Source

pub fn cursor_position(&self) -> Position

Get cursor position

Source

pub fn selection(&self) -> Option<&Selection>

Get selection range

Source

pub fn secondary_selections(&self) -> &[Selection]

Get secondary selections/cursors (multi-cursor)

Source

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.styles will interval_tree + style_layers merged from
  • Supportcode folding (based folding_manager)

Note: This API is not responsible for mapping StyleId to specific colors.

Source

pub fn visual_line_count(&self) -> usize

Get total visual line count (considering soft wrapping + folding).

Source

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.

Source

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.

Source

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.

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