Skip to main content

Code

Struct Code 

Source
pub struct Code { /* private fields */ }

Implementations§

Source§

impl Code

Source

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.

Source

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

Source

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

Source

pub fn get_content(&self) -> String

Source

pub fn slice(&self, start: usize, end: usize) -> String

Source

pub fn len(&self) -> usize

Source

pub fn len_lines(&self) -> usize

Source

pub fn len_chars(&self) -> usize

Source

pub fn line_to_char(&self, line_idx: usize) -> usize

Source

pub fn char_to_byte(&self, char_idx: usize) -> usize

Source

pub fn line_len(&self, idx: usize) -> usize

Source

pub fn line(&self, line_idx: usize) -> RopeSlice<'_>

Source

pub fn char_to_line(&self, char_idx: usize) -> usize

Source

pub fn char_slice(&self, start: usize, end: usize) -> RopeSlice<'_>

Source

pub fn byte_slice(&self, start: usize, end: usize) -> RopeSlice<'_>

Source

pub fn byte_to_line(&self, byte_idx: usize) -> usize

Source

pub fn byte_to_char(&self, byte_idx: usize) -> usize

Source

pub fn tx(&mut self)

Source

pub fn set_state_before(&mut self, offset: usize, selection: Option<Selection>)

Source

pub fn set_state_after(&mut self, offset: usize, selection: Option<Selection>)

Source

pub fn commit(&mut self)

Source

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

Source

pub fn remove(&mut self, from: usize, to: usize)

Source

pub fn is_highlight(&self) -> bool

Source

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.

Source

pub fn undo(&mut self) -> Option<EditBatch>

Source

pub fn redo(&mut self) -> Option<EditBatch>

Source

pub fn word_boundaries(&self, pos: usize) -> (usize, usize)

Source

pub fn line_boundaries(&self, pos: usize) -> (usize, usize)

Source

pub fn indent(&self) -> String

Source

pub fn comment(&self) -> String

Source

pub fn indentation_level(&self, line: usize, col: usize) -> usize

Source

pub fn is_only_indentation_before(&self, r: usize, c: usize) -> bool

Source

pub fn find_indent_at_line_start(&self, line_idx: usize) -> Option<usize>

Source

pub fn smart_paste(&mut self, offset: usize, text: &str) -> usize

Paste text with indentation awareness.

  1. Determine the indentation level at the cursor (base_level).
  2. The first line of the pasted block is inserted at the cursor level (trimmed).
  3. 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 diff to prev_nonempty_level to calculate the new insertion level.
  4. 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.

Source

pub fn set_change_callback( &mut self, callback: Box<dyn Fn(Vec<(usize, usize, usize, usize, String)>)>, )

Set the change callback function for handling document changes

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> 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.