pub struct Buffer { /* private fields */ }Expand description
Per-document state shared across all crate::View views of the
same file. Wrap in Arc<Mutex<Buffer>> and pass to
crate::View::new_view to create an additional window onto the
same content.
Uses a ropey::Rope for O(log N) edits and O(1) byte-length queries.
The rope always contains at least one logical line: a freshly constructed
Buffer holds an empty rope (which ropey reports as 1 line) so
cursor positions never need an “is the buffer empty?” branch.
§Line semantics
ropey::Rope::len_lines() and split('\n').count() agree for all inputs:
""→ 1 line"foo\n"→ 2 lines (trailing empty line)"a\nb\n"→ 3 lines
Rope::line(i) returns a RopeSlice that includes the trailing \n
for non-final lines. Public accessors strip it before returning String.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn from_str(text: &str) -> Self
pub fn from_str(text: &str) -> Self
Build content from a flat string. Splits on \n; a trailing
\n produces a trailing empty line (matches ropey’s own convention).
Sourcepub fn undo_group_enter(&mut self)
pub fn undo_group_enter(&mut self)
Open (nest into) an undo group. On the outermost open (depth 0→1)
record the current dirty_gen and disarm, so the group’s first
mutating push_undo takes exactly one snapshot.
Sourcepub fn undo_group_exit(&mut self)
pub fn undo_group_exit(&mut self)
Close (unnest) an undo group. On the outermost close (depth 1→0), if
the group armed a snapshot but dirty_gen is unchanged since it opened
(nothing was mutated), pop that snapshot so a no-op group leaves zero
undo entries. Resets the group flags.
Sourcepub fn undo_group_active(&self) -> bool
pub fn undo_group_active(&self) -> bool
Whether an undo group is currently open (depth > 0).
Sourcepub fn undo_group_arm(&mut self) -> bool
pub fn undo_group_arm(&mut self) -> bool
Arm the open group’s single snapshot. Returns true if this call armed
it (the first mutating push_undo in the group, which must take the
snapshot), false if it was already armed (a later push to suppress).