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
impl LineIndex
Sourcepub fn from_text(text: &str) -> Self
pub fn from_text(text: &str) -> Self
Build line index from already-normalized internal text.
This low-level constructor does not normalize line endings. Higher-level editor entry points
normalize CRLF and lone CR to LF before constructing LineIndex; direct CRLF input here keeps
\r as ordinary line content.
Sourcepub fn delete_line(&mut self, line_number: usize)
pub fn delete_line(&mut self, line_number: usize)
Delete the specified line
Sourcepub fn get_line(&self, line_number: usize) -> Option<LineMetadata>
pub fn get_line(&self, line_number: usize) -> Option<LineMetadata>
Get metadata for the specified line number (simulated)
Sourcepub fn line_to_offset(&self, line_number: usize) -> usize
👎Deprecated: legacy byte offset excludes previous LF separators; use position_to_char_offset plus char_offset_to_byte_offset
pub fn line_to_offset(&self, line_number: usize) -> usize
legacy byte offset excludes previous LF separators; use position_to_char_offset plus char_offset_to_byte_offset
Legacy byte offset for a line start, excluding previous LF separator bytes.
Prefer LineIndex::position_to_char_offset plus
LineIndex::char_offset_to_byte_offset for offsets in the canonical document text. This
compatibility method preserves the older byte-offset convention where previous \n bytes are
not counted. If this index was built directly from CRLF text, \r remains line content and is
counted.
Sourcepub fn offset_to_line(&self, offset: usize) -> usize
👎Deprecated: legacy byte offset excludes previous LF separators; use byte_offset_to_char_offset plus char_offset_to_position
pub fn offset_to_line(&self, offset: usize) -> usize
legacy byte offset excludes previous LF separators; use byte_offset_to_char_offset plus char_offset_to_position
Legacy line lookup from a byte offset that excludes previous LF separator bytes.
Prefer LineIndex::byte_offset_to_char_offset plus LineIndex::char_offset_to_position
for offsets in the canonical document text. This compatibility method uses the same legacy
convention as LineIndex::line_to_offset.
Sourcepub fn char_offset_to_position(&self, char_offset: usize) -> (usize, usize)
pub fn char_offset_to_position(&self, char_offset: usize) -> (usize, usize)
Get line number and offset within line from character offset
Sourcepub fn position_to_char_offset(&self, line: usize, column: usize) -> usize
pub fn position_to_char_offset(&self, line: usize, column: usize) -> usize
Get character offset from line number and column number
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Get total line count
Sourcepub fn byte_count(&self) -> usize
pub fn byte_count(&self) -> usize
Get total byte count
Sourcepub fn char_count(&self) -> usize
pub fn char_count(&self) -> usize
Get total character count
Sourcepub fn char_at(&self, char_offset: usize) -> Option<char>
pub fn char_at(&self, char_offset: usize) -> Option<char>
Get the character at the specified character offset (Unicode scalar index).
Returns None if char_offset is out of bounds.
Sourcepub fn char_offset_to_byte_offset(&self, char_offset: usize) -> usize
pub fn char_offset_to_byte_offset(&self, char_offset: usize) -> usize
Convert a character offset (Unicode scalar values) to a UTF-8 byte offset.
The returned byte offset is clamped to the document length.
Sourcepub fn byte_offset_to_char_offset(&self, byte_offset: usize) -> usize
pub fn byte_offset_to_char_offset(&self, byte_offset: usize) -> usize
Convert a UTF-8 byte offset to a character offset (Unicode scalar values).
The returned character offset is clamped to the document length.
Sourcepub fn char_offset_to_line_byte_column(
&self,
char_offset: usize,
) -> (usize, usize)
pub fn char_offset_to_line_byte_column( &self, char_offset: usize, ) -> (usize, usize)
Convert a character offset to (line, byte_column) where byte_column is measured in UTF-8 bytes.
Sourcepub fn insert(&mut self, char_offset: usize, text: &str)
pub fn insert(&mut self, char_offset: usize, text: &str)
Insert text (at specified character offset)
Sourcepub fn delete(&mut self, start_char: usize, len_chars: usize)
pub fn delete(&mut self, start_char: usize, len_chars: usize)
Delete text range (character offset)
Sourcepub fn get_range(&self, start_char: usize, len_chars: usize) -> String
pub fn get_range(&self, start_char: usize, len_chars: usize) -> String
Get text in the specified character range.
Sourcepub fn get_line_text(&self, line_number: usize) -> Option<String>
pub fn get_line_text(&self, line_number: usize) -> Option<String>
Get text of the specified line (excluding newline)