pub struct Code { /* private fields */ }Implementations§
Source§impl Code
impl Code
Sourcepub fn new(
text: &str,
lang: &str,
custom_highlights: Option<HashMap<String, String>>,
) -> Result<Self>
pub fn new( text: &str, lang: &str, custom_highlights: Option<HashMap<String, String>>, ) -> Result<Self>
Create a new Code instance with the given text and language.
pub fn point(&self, offset: usize) -> (usize, usize)
pub fn offset(&self, row: usize, col: usize) -> usize
pub fn get_content(&self) -> String
pub fn slice(&self, start: usize, end: usize) -> String
pub fn len(&self) -> usize
pub fn len_lines(&self) -> usize
pub fn len_chars(&self) -> usize
pub fn line_to_char(&self, line_idx: usize) -> usize
pub fn char_to_byte(&self, char_idx: usize) -> usize
pub fn line_len(&self, idx: usize) -> usize
pub fn line(&self, line_idx: usize) -> RopeSlice<'_>
pub fn char_to_line(&self, char_idx: usize) -> usize
pub fn char_slice(&self, start: usize, end: usize) -> RopeSlice<'_>
pub fn byte_slice(&self, start: usize, end: usize) -> RopeSlice<'_>
pub fn byte_to_line(&self, byte_idx: usize) -> usize
pub fn byte_to_char(&self, byte_idx: usize) -> usize
pub fn tx(&mut self)
pub fn set_state_before(&mut self, offset: usize, selection: Option<Selection>)
pub fn set_state_after(&mut self, offset: usize, selection: Option<Selection>)
pub fn commit(&mut self)
pub fn insert(&mut self, from: usize, text: &str)
pub fn remove(&mut self, from: usize, to: usize)
pub fn is_highlight(&self) -> bool
Sourcepub fn highlight_interval<T: Copy>(
&self,
start: usize,
end: usize,
theme: &HashMap<String, T>,
) -> Vec<(usize, usize, T)>
pub fn highlight_interval<T: Copy>( &self, start: usize, end: usize, theme: &HashMap<String, T>, ) -> Vec<(usize, usize, T)>
Highlights the interval between start and end char indices.
Returns a list of (start byte, end byte, token_name) for highlighting.
pub fn undo(&mut self) -> Option<EditBatch>
pub fn redo(&mut self) -> Option<EditBatch>
pub fn word_boundaries(&self, pos: usize) -> (usize, usize)
pub fn line_boundaries(&self, pos: usize) -> (usize, usize)
pub fn indent(&self) -> String
pub fn comment(&self) -> String
pub fn indentation_level(&self, line: usize, col: usize) -> usize
pub fn is_only_indentation_before(&self, r: usize, c: usize) -> bool
pub fn find_indent_at_line_start(&self, line_idx: usize) -> Option<usize>
Sourcepub fn smart_paste(&mut self, offset: usize, text: &str) -> usize
pub fn smart_paste(&mut self, offset: usize, text: &str) -> usize
Paste text with indentation awareness.
- Determine the indentation level at the cursor (
base_level). - The first line of the pasted block is inserted at the cursor level (trimmed).
- Subsequent lines adjust their indentation relative to the previous non-empty line in the pasted block:
- Compute
diff= change in indentation from the previous non-empty line in the source block (clamped ±1). - Apply
difftoprev_nonempty_levelto calculate the new insertion level.
- Compute
- Empty lines are inserted as-is and do not affect subsequent indentation.
This ensures that pasted blocks keep their relative structure while aligning to the cursor.
Inserts text with indentation-awareness at offset.
Returns number of characters inserted.
Auto Trait Implementations§
impl Freeze for Code
impl !RefUnwindSafe for Code
impl !Send for Code
impl !Sync for Code
impl Unpin for Code
impl UnsafeUnpin for Code
impl !UnwindSafe for Code
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more