Skip to main content

EditorCore

Struct EditorCore 

Source
pub struct EditorCore { /* private fields */ }
Expand description

Editor Core state

EditorCore aggregates all underlying editor components, including:

  • LineIndex: Rope-backed canonical text buffer with 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");

Implementations§

Source§

impl EditorCore

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 get_minimap_grid( &self, start_visual_row: usize, count: usize, ) -> MinimapGrid

Get a lightweight minimap snapshot (by visual line).

Compared with Self::get_headless_grid_styled, this API returns aggregated per-line summaries instead of per-character cells, which is intended for minimap-like overviews.

Source

pub fn get_headless_grid_composed( &self, start_visual_row: usize, count: usize, ) -> ComposedGrid

Get a decoration-aware composed grid snapshot (by composed visual line).

This is an optional snapshot path that injects:

  • inline virtual text (DecorationPlacement::{Before,After}), e.g. inlay hints
  • above-line virtual text (DecorationPlacement::AboveLine), e.g. code lens

Notes:

  • Wrapping is still computed from the underlying document text only.
  • Virtual text can therefore extend past the viewport width; hosts may clip.
  • Each ComposedCell carries its origin (Document vs Virtual) so hosts can map interactions back to document offsets without re-implementing layout.
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 text_range(&self, start: usize, len: usize) -> String

Get a text range by character offset and length.

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 set_word_boundary_ascii_boundary_chars(&mut self, boundary_chars: &str)

Override the ASCII word-boundary character set used by editor-friendly “word” operations.

See WordBoundaryConfig::set_ascii_boundary_chars.

Source

pub fn reset_word_boundary_defaults(&mut self)

Reset word-boundary configuration to the default (ASCII identifier-like words).

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 line_index(&self) -> &LineIndex

Get the canonical line index and text access facade.

Source

pub fn layout_engine(&self) -> &LayoutEngine

Get the current layout engine state.

Source

pub fn interval_tree(&self) -> &IntervalTree

Get the base style interval tree.

Source

pub fn style_layers(&self) -> &BTreeMap<StyleLayerId, IntervalTree>

Get all style layers.

Source

pub fn style_layer(&self, layer: StyleLayerId) -> Option<&IntervalTree>

Get one style layer by id.

Source

pub fn diagnostics(&self) -> &[Diagnostic]

Get the current diagnostics list.

Source

pub fn decorations(&self) -> &BTreeMap<DecorationLayerId, Vec<Decoration>>

Get all decoration layers.

Source

pub fn decorations_for_layer(&self, layer: DecorationLayerId) -> &[Decoration]

Get all decorations for a given layer.

Source

pub fn document_symbols(&self) -> &DocumentOutline

Get the current document outline.

Source

pub fn folding_manager(&self) -> &FoldingManager

Get the folding manager as a read-only view.

Source

pub fn viewport_width(&self) -> usize

Get the current viewport width in cells.

Source

pub fn invalidate_visual_row_index_cache(&mut self)

Invalidate cached visual-row index (wrap/folding derived mapping).

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.

Source

pub fn visual_position_to_logical( &self, visual_row: usize, x_in_cells: usize, ) -> Option<Position>

Convert visual coordinates (global visual row + x in cells) back to logical (line, column).

  • visual_row is the global visual row (after soft wrapping and folding).
  • x_in_cells is the cell offset within that visual row (0-based).

Returns None if layout information is unavailable.

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.