pub struct Buffer { /* private fields */ }Expand description
A single editable text buffer.
Thread ownership: only the caller-selected engine thread mutates a Buffer.
All other threads receive RopeSnapshots instead.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn synthetic_read_only(text: &str) -> Self
pub fn synthetic_read_only(text: &str) -> Self
A synthetic, read-only buffer pre-populated with text.
“Synthetic” means the buffer is never persisted: no row in the
buffers table, no buffer_edits, no buffer_snapshots, never
surfaced in FTS5 or find-in-all. The rope lives only in memory
for the lifetime of the process. “Read-only” means the core
thread rejects any EditOp or [crate::SelectionEdit] before
it reaches the rope.
Used for transient documentation surfaces such as the tutorial tab.
Sourcepub fn from_parts(id: BufferId, text: &str, revision: Revision) -> Self
pub fn from_parts(id: BufferId, text: &str, revision: Revision) -> Self
Reconstruct a buffer with a specific id and revision (for persistence
recovery). The revision should be the revision the snapshot was
taken at; subsequent Self::apply calls advance it normally.
Sourcepub fn from_parts_with_file(
id: BufferId,
text: &str,
revision: Revision,
file: Option<FileAssociation>,
) -> Self
pub fn from_parts_with_file( id: BufferId, text: &str, revision: Revision, file: Option<FileAssociation>, ) -> Self
Reconstruct a buffer with a specific id, revision, and file association.
Sourcepub fn is_synthetic(&self) -> bool
pub fn is_synthetic(&self) -> bool
true when this buffer is synthetic (never persisted).
Persist clients check this before issuing any write; the core
thread skips persist.touch_buffer / persist.upsert_buffer /
persist.save_snapshot_async / persist.write_edit for
synthetic buffers.
Sourcepub fn is_read_only(&self) -> bool
pub fn is_read_only(&self) -> bool
true when this buffer rejects edit application.
The core thread checks this before dispatching to
apply_one_edit / apply_selection_edit and returns
Error::ReadOnly without touching the rope. Undo / redo
operations also no-op on read-only buffers.
Sourcepub fn selections(&self) -> &[Selection]
pub fn selections(&self) -> &[Selection]
Borrow the selections.
Sourcepub fn set_selections(&mut self, selections: Vec<Selection>)
pub fn set_selections(&mut self, selections: Vec<Selection>)
Replace the selection set.
Sourcepub fn undo_tree_mut(&mut self) -> &mut UndoTree
pub fn undo_tree_mut(&mut self) -> &mut UndoTree
Mutable borrow of the undo tree. Used by the engine owner to insert groups, append records, and step the current pointer along the undo / redo path.
Sourcepub fn file_association(&self) -> Option<&FileAssociation>
pub fn file_association(&self) -> Option<&FileAssociation>
Borrow the optional filesystem association.
Sourcepub fn set_file_association(&mut self, file: Option<FileAssociation>)
pub fn set_file_association(&mut self, file: Option<FileAssociation>)
Replace the filesystem association.
Sourcepub fn capture_removed_text(&self, op: &EditOp) -> Result<String, Error>
pub fn capture_removed_text(&self, op: &EditOp) -> Result<String, Error>
Capture the substring op would remove from the current rope, if
any. Returns an empty String for EditOp::Insert.
§Errors
Returns Error::Text if the range falls outside the rope.
Sourcepub fn snapshot(&self) -> RopeSnapshot
pub fn snapshot(&self) -> RopeSnapshot
Take a cheap, send-able snapshot of the current rope + revision.
Sourcepub fn title(&self, max_chars: usize) -> Option<String>
pub fn title(&self, max_chars: usize) -> Option<String>
First non-empty trimmed line of the rope, clipped to max_chars. An
empty buffer (or a buffer of pure whitespace) returns None.
Used for buffer-switcher labels and the windows.tabs table when no
user-set title exists.
Sourcepub fn running_checksum(&self) -> u64
pub fn running_checksum(&self) -> u64
FNV-1a 64-bit hash of the rope’s bytes, maintained incrementally
across Self::apply calls. The core thread persists this as
buffer_edits.checksum_after; a divergence from a full-walk
recomputation is surfaced through event:checksum_drift. See
crate::checksum.
Sourcepub fn edits_since_verify(&self) -> u32
pub fn edits_since_verify(&self) -> u32
Number of Self::apply calls since the running checksum was
last cross-checked against a full-walk recomputation.
Sourcepub fn verify_running_checksum(&mut self) -> (u64, u64)
pub fn verify_running_checksum(&mut self) -> (u64, u64)
Re-run a full-walk FNV-1a over the current rope and reseat the
running checksum to the freshly-computed value. Returns
(observed_before, computed) — observed_before is what the
running counter held before reseating; equality means no drift.
Also clears Self::edits_since_verify so the next verification
is again CHECKSUM_VERIFY_INTERVAL edits away.
Sourcepub fn apply(&mut self, op: &EditOp) -> Result<Revision, Error>
pub fn apply(&mut self, op: &EditOp) -> Result<Revision, Error>
Apply an EditOp, advance the revision, and return the new revision.
§Errors
Returns Error::Text if any position in op falls outside the rope.
Returns Error::ReadOnly if the buffer is read-only (e.g. a
synthetic tutorial buffer); the rope is not touched.