Skip to main content

Buffer

Struct Buffer 

Source
pub struct Buffer {
    pub path: Option<PathBuf>,
    pub scroll: usize,
    pub scroll_x: usize,
    pub markers: Vec<Marker>,
    pub file_hash: Option<u64>,
    pub file_mtime: Option<u64>,
    pub file_size: Option<u64>,
    pub external_modification_detected: bool,
    pub is_saving: bool,
    /* private fields */
}

Fields§

§path: Option<PathBuf>§scroll: usize§scroll_x: usize§markers: Vec<Marker>§file_hash: Option<u64>

Hash of the file content at last save (for detecting external modifications).

§file_mtime: Option<u64>

Modification time of the file at last save (for quick pre-check).

§file_size: Option<u64>

Size of the file at last save (for quick pre-check).

§external_modification_detected: bool

Set to true when an external modification is detected.

§is_saving: bool

Set to true during save to ignore file watcher events.

Implementations§

Source§

impl Buffer

Source

pub fn new() -> Self

Source

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

Source

pub fn from_lines(lines: Vec<String>, path: Option<PathBuf>) -> Self

Source

pub fn open(path: &Path) -> Result<Self>

Source

pub fn restore( path: PathBuf, lines: Vec<String>, selection: Option<Selection>, scroll: usize, dirty: bool, markers: Vec<Marker>, undo_stack: Vec<SerializableSnapshot>, redo_stack: Vec<SerializableSnapshot>, ) -> Self

Source

pub fn id(&self) -> BufferId

Source

pub fn version(&self) -> Version

Source

pub fn snapshot(&self) -> BufferSnapshot

Source

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

Convert a Position to a global char index using ropey’s char metric.

Source

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

Convert a global char index to a Position.

Source

pub fn cursor(&self) -> Position

Source

pub fn selection(&self) -> Option<Selection>

Source

pub fn set_cursor(&mut self, pos: Position)

Source

pub fn set_selection(&mut self, selection: Option<Selection>)

Source

pub fn normalize_position(&self, pos: Position) -> Position

Clamp pos to a valid (line, column) within the current text.

Source

pub fn normalize_cursor(&mut self)

Source

pub fn line_count(&self) -> usize

Source

pub fn current_line(&self) -> usize

Source

pub fn char_count(&self) -> usize

Source

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

Source

pub fn lines(&self) -> Vec<String>

Source

pub fn lines_arc(&mut self) -> Arc<Vec<String>>

Return a shared Arc<Vec<String>> for the current buffer contents. The result is cached and invalidated on mutations to avoid rebuilding the Vec for every highlight request.

Source

pub fn is_empty(&self) -> bool

Source

pub fn is_dirty(&self) -> bool

Source

pub fn can_undo(&self) -> bool

Source

pub fn can_redo(&self) -> bool

Source

pub fn history_len(&self) -> usize

Source

pub fn history_position(&self) -> usize

Source

pub fn apply_change(&mut self, change: ChangeSet, kind: ChangeKind)

Source

pub fn begin_transaction(&mut self, kind: ChangeKind)

Begin an explicit transaction. All subsequent calls to Buffer::apply_change will buffer their ops instead of writing to history. Call Buffer::end_transaction to commit everything as one undo step.

If a transaction is already active this is a no-op (the outermost transaction wins). In debug builds a panic is emitted to surface accidental nesting early.

Source

pub fn end_transaction(&mut self)

Commit the current transaction to history as a single undo step.

  • The committed entry always gets its own history slot — try_merge is bypassed, so the transaction is never accidentally coalesced with surrounding typing.
  • history.push truncates any future (redo) entries, so a transaction after undo correctly discards the forward branch.
  • increment_version is called on commit so the buffer version advances once for the whole group (consistent with LSP sync).

If no transaction is active, or if no ops were recorded, this is a no-op.

Source

pub fn abort_transaction(&mut self)

Discard the current transaction without recording a history entry.

⚠️ Text mutations that occurred within the transaction are not rolled back — only the pending history entry is dropped. The buffer will be in a modified-but-untracked state after this call. Use this only when you intend to handle the rollback yourself (e.g. by reloading from disk), or when you are certain no edits were made.

Source

pub fn in_transaction(&self) -> bool

Returns true if a transaction is currently open.

Source

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

Source

pub fn delete_backward(&mut self)

Source

pub fn delete_forward(&mut self)

Source

pub fn delete_range(&mut self, start_pos: Position, end_pos: Position)

Source

pub fn replace_range(&mut self, start: Position, end: Position, text: &str)

Source

pub fn insert_newline(&mut self)

Source

pub fn insert_newline_with_indent( &mut self, _use_spaces: bool, _indent_width: usize, )

Source

pub fn delete_word_backward(&mut self)

Source

pub fn delete_word_forward(&mut self)

Source

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

Source

pub fn insert_at(&mut self, pos: Position, text: &str)

Source

pub fn insert_text_raw(&mut self, text: &str)

Source

pub fn delete_line(&mut self) -> String

Source

pub fn selected_text_all(&self) -> String

Source

pub fn cursor_left(&mut self) -> Position

Source

pub fn offset_left(&self, pos: Position) -> Position

Source

pub fn cursor_right(&mut self) -> Position

Source

pub fn offset_right(&self, pos: Position) -> Position

Source

pub fn cursor_up(&mut self) -> Position

Source

pub fn offset_up(&self, pos: Position) -> Position

Source

pub fn cursor_down(&mut self) -> Position

Source

pub fn offset_down(&self, pos: Position) -> Position

Source

pub fn cursor_up_n(&mut self, n: usize) -> Position

Source

pub fn offset_up_n(&self, pos: Position, n: usize) -> Position

Source

pub fn cursor_down_n(&mut self, n: usize) -> Position

Source

pub fn offset_down_n(&self, pos: Position, n: usize) -> Position

Source

pub fn cursor_page_up(&mut self, height: usize) -> Position

Source

pub fn cursor_page_down(&mut self, height: usize) -> Position

Source

pub fn cursor_line_start(&mut self) -> Position

Source

pub fn offset_line_start(&self, pos: Position) -> Position

Source

pub fn cursor_line_end(&mut self) -> Position

Source

pub fn offset_line_end(&self, pos: Position) -> Position

Source

pub fn cursor_word_prev(&mut self) -> Position

Source

pub fn cursor_word_next(&mut self) -> Position

Source

pub fn word_boundary_prev(&self, pos: Position) -> Position

Source

pub fn word_boundary_next(&self, pos: Position) -> Position

Source

pub fn word_boundary_next_for_selection(&self, pos: Position) -> Position

Source

pub fn select_all(&mut self)

Source

pub fn selected_text(&self) -> String

Source

pub fn delete_selection(&mut self) -> String

Source

pub fn undo(&mut self) -> bool

Source

pub fn redo(&mut self) -> bool

Source

pub fn undo_stack(&self) -> Vec<SerializableSnapshot>

Source

pub fn redo_stack(&self) -> Vec<SerializableSnapshot>

Source

pub fn save(&mut self, settings: &Settings) -> Result<()>

Source

pub fn compute_hash(text: &Rope) -> Option<u64>

Source

pub fn compute_file_hash(path: &Path) -> Option<u64>

Source

pub fn get_file_metadata(path: &Path) -> Option<(u64, u64)>

Source

pub fn compute_and_store_file_hash(&mut self)

Source

pub fn check_external_modification(&mut self) -> bool

Source

pub fn reload_from_disk(&mut self) -> Result<()>

Source

pub fn clear_external_modification(&mut self)

Source

pub fn scroll_to_cursor(&mut self, height: usize)

Source

pub fn scroll_to_cursor_visual( &mut self, height: usize, _content_width: usize, _indent_width: usize, )

Source

pub fn scroll_x_to_cursor( &mut self, _content_width: usize, _indent_width: usize, )

Source

pub fn slice(&self, range: Range<Position>) -> String

Source

pub fn text(&self) -> String

Source

pub fn apply_op_without_history(&mut self, op: &BufferOp)

Trait Implementations§

Source§

impl Debug for Buffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Buffer

Source§

fn default() -> Self

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

impl From<&Buffer> for SerializableSnapshot

Source§

fn from(buf: &Buffer) -> Self

Converts to this type from the input type.
Source§

impl From<&Rope> for Buffer

Source§

fn from(rope: &Rope) -> Self

Converts to this type from the input type.

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.