Skip to main content

LineIndex

Struct LineIndex 

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

Logical line index - implemented using Rope data structure

Rope provides O(log N) line access, insertion, and deletion performance, suitable for large file editing

Implementations§

Source§

impl LineIndex

Source

pub fn new() -> Self

Create a new line index

Source

pub fn from_text(text: &str) -> Self

Build line index from text

Source

pub fn append_line(&mut self, line: LineMetadata)

Append a new line

Source

pub fn insert_line(&mut self, line_number: usize, line: LineMetadata)

Insert a line at the specified position

Source

pub fn delete_line(&mut self, line_number: usize)

Delete the specified line

Source

pub fn get_line(&self, line_number: usize) -> Option<LineMetadata>

Get metadata for the specified line number (simulated)

Source

pub fn get_line_mut(&mut self, line_number: usize) -> Option<&mut LineMetadata>

Get mutable reference (Rope doesn’t need this method, kept for compatibility)

Source

pub fn line_to_offset(&self, line_number: usize) -> usize

Get byte offset for line number (excluding newlines of previous lines)

Source

pub fn offset_to_line(&self, offset: usize) -> usize

Get line number from byte offset (offset excludes newlines)

Source

pub fn char_offset_to_position(&self, char_offset: usize) -> (usize, usize)

Get line number and offset within line from character offset

Source

pub fn position_to_char_offset(&self, line: usize, column: usize) -> usize

Get character offset from line number and column number

Source

pub fn line_count(&self) -> usize

Get total line count

Source

pub fn byte_count(&self) -> usize

Get total byte count

Source

pub fn char_count(&self) -> usize

Get total character count

Source

pub fn insert(&mut self, char_offset: usize, text: &str)

Insert text (at specified character offset)

Source

pub fn delete(&mut self, start_char: usize, len_chars: usize)

Delete text range (character offset)

Source

pub fn get_text(&self) -> String

Get complete text

Source

pub fn get_line_text(&self, line_number: usize) -> Option<String>

Get text of the specified line (excluding newline)

Trait Implementations§

Source§

impl Default for LineIndex

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.