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: boolSet to true when an external modification is detected.
is_saving: boolSet to true during save to ignore file watcher events.
Implementations§
Source§impl Buffer
impl Buffer
pub fn new() -> Self
pub fn from_text(text: &str) -> Self
pub fn from_lines(lines: Vec<String>, path: Option<PathBuf>) -> Self
pub fn open(path: &Path) -> Result<Self>
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
pub fn id(&self) -> BufferId
pub fn version(&self) -> Version
pub fn snapshot(&self) -> BufferSnapshot
Sourcepub fn pos_to_char(&self, pos: Position) -> usize
pub fn pos_to_char(&self, pos: Position) -> usize
Convert a Position to a global char index using ropey’s char metric.
Sourcepub fn char_to_pos(&self, char_idx: usize) -> Position
pub fn char_to_pos(&self, char_idx: usize) -> Position
Convert a global char index to a Position.
pub fn cursor(&self) -> Position
pub fn selection(&self) -> Option<Selection>
pub fn set_cursor(&mut self, pos: Position)
pub fn set_selection(&mut self, selection: Option<Selection>)
Sourcepub fn normalize_position(&self, pos: Position) -> Position
pub fn normalize_position(&self, pos: Position) -> Position
Clamp pos to a valid (line, column) within the current text.
pub fn normalize_cursor(&mut self)
pub fn line_count(&self) -> usize
pub fn current_line(&self) -> usize
pub fn char_count(&self) -> usize
pub fn line(&self, line_idx: usize) -> Option<String>
pub fn lines(&self) -> Vec<String>
Sourcepub fn lines_arc(&mut self) -> Arc<Vec<String>>
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.
pub fn is_empty(&self) -> bool
pub fn is_dirty(&self) -> bool
pub fn can_undo(&self) -> bool
pub fn can_redo(&self) -> bool
pub fn history_len(&self) -> usize
pub fn history_position(&self) -> usize
pub fn apply_change(&mut self, change: ChangeSet, kind: ChangeKind)
Sourcepub fn begin_transaction(&mut self, kind: ChangeKind)
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.
Sourcepub fn end_transaction(&mut self)
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_mergeis bypassed, so the transaction is never accidentally coalesced with surrounding typing. history.pushtruncates any future (redo) entries, so a transaction after undo correctly discards the forward branch.increment_versionis 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.
Sourcepub fn abort_transaction(&mut self)
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.
Sourcepub fn in_transaction(&self) -> bool
pub fn in_transaction(&self) -> bool
Returns true if a transaction is currently open.
pub fn insert(&mut self, text: &str)
pub fn delete_backward(&mut self)
pub fn delete_forward(&mut self)
pub fn delete_range(&mut self, start_pos: Position, end_pos: Position)
pub fn replace_range(&mut self, start: Position, end: Position, text: &str)
pub fn insert_newline(&mut self)
pub fn insert_newline_with_indent( &mut self, _use_spaces: bool, _indent_width: usize, )
pub fn delete_word_backward(&mut self)
pub fn delete_word_forward(&mut self)
pub fn word_range_at(&self, pos: Position) -> (usize, usize)
pub fn insert_at(&mut self, pos: Position, text: &str)
pub fn insert_text_raw(&mut self, text: &str)
pub fn delete_line(&mut self) -> String
pub fn selected_text_all(&self) -> String
pub fn cursor_left(&mut self) -> Position
pub fn offset_left(&self, pos: Position) -> Position
pub fn cursor_right(&mut self) -> Position
pub fn offset_right(&self, pos: Position) -> Position
pub fn cursor_up(&mut self) -> Position
pub fn offset_up(&self, pos: Position) -> Position
pub fn cursor_down(&mut self) -> Position
pub fn offset_down(&self, pos: Position) -> Position
pub fn cursor_up_n(&mut self, n: usize) -> Position
pub fn offset_up_n(&self, pos: Position, n: usize) -> Position
pub fn cursor_down_n(&mut self, n: usize) -> Position
pub fn offset_down_n(&self, pos: Position, n: usize) -> Position
pub fn cursor_page_up(&mut self, height: usize) -> Position
pub fn cursor_page_down(&mut self, height: usize) -> Position
pub fn cursor_line_start(&mut self) -> Position
pub fn offset_line_start(&self, pos: Position) -> Position
pub fn cursor_line_end(&mut self) -> Position
pub fn offset_line_end(&self, pos: Position) -> Position
pub fn cursor_word_prev(&mut self) -> Position
pub fn cursor_word_next(&mut self) -> Position
pub fn word_boundary_prev(&self, pos: Position) -> Position
pub fn word_boundary_next(&self, pos: Position) -> Position
pub fn word_boundary_next_for_selection(&self, pos: Position) -> Position
pub fn select_all(&mut self)
pub fn selected_text(&self) -> String
pub fn delete_selection(&mut self) -> String
pub fn undo(&mut self) -> bool
pub fn redo(&mut self) -> bool
pub fn undo_stack(&self) -> Vec<SerializableSnapshot>
pub fn redo_stack(&self) -> Vec<SerializableSnapshot>
pub fn save(&mut self, settings: &Settings) -> Result<()>
pub fn compute_hash(text: &Rope) -> Option<u64>
pub fn compute_file_hash(path: &Path) -> Option<u64>
pub fn get_file_metadata(path: &Path) -> Option<(u64, u64)>
pub fn compute_and_store_file_hash(&mut self)
pub fn check_external_modification(&mut self) -> bool
pub fn reload_from_disk(&mut self) -> Result<()>
pub fn clear_external_modification(&mut self)
pub fn scroll_to_cursor(&mut self, height: usize)
pub fn scroll_to_cursor_visual( &mut self, height: usize, _content_width: usize, _indent_width: usize, )
pub fn scroll_x_to_cursor( &mut self, _content_width: usize, _indent_width: usize, )
pub fn slice(&self, range: Range<Position>) -> String
pub fn text(&self) -> String
pub fn apply_op_without_history(&mut self, op: &BufferOp)
Trait Implementations§
Source§impl From<&Buffer> for SerializableSnapshot
impl From<&Buffer> for SerializableSnapshot
Auto Trait Implementations§
impl Freeze for Buffer
impl RefUnwindSafe for Buffer
impl Send for Buffer
impl Sync for Buffer
impl Unpin for Buffer
impl UnsafeUnpin for Buffer
impl UnwindSafe for Buffer
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
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>
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>
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