pub struct BufferSnapshot {
pub id: BufferId,
pub lines: Vec<String>,
pub cursor: Cursor,
pub file_path: Option<String>,
pub modified: bool,
}Expand description
Read-only snapshot of buffer state.
A BufferSnapshot captures the complete state of a buffer at a point
in time. It’s cheap to clone and safe to share across threads.
§Cursor Isolation (#471)
Cursor is passed explicitly to from_buffer() - get it from Window.
§Immutability
All methods are read-only. The snapshot cannot be modified after creation, ensuring thread safety without locks.
§Fields Captured
id: Buffer identifierlines: All text linescursor: Cursor state (passed from Window)file_path: Associated file path (if any)modified: Whether buffer had unsaved changes
Note: Selection removed in Phase 8 (#465) - it now lives in Window. Note: Cursor removed from Buffer in #471 - it now lives in Window.
Fields§
§id: BufferIdBuffer identifier.
lines: Vec<String>Text content as lines.
cursor: CursorCursor state (from Window, not Buffer).
file_path: Option<String>File path (if buffer is associated with a file).
modified: boolWhether buffer has unsaved modifications.
Implementations§
Source§impl BufferSnapshot
impl BufferSnapshot
Sourcepub fn from_buffer(buffer: &Buffer, cursor: Cursor) -> Self
pub fn from_buffer(buffer: &Buffer, cursor: Cursor) -> Self
Create a snapshot from a buffer.
Cursor must be passed explicitly - get it from Window. This clones all buffer state, so the snapshot is independent of subsequent buffer modifications.
Sourcepub const fn new(
id: BufferId,
lines: Vec<String>,
cursor: Cursor,
file_path: Option<String>,
modified: bool,
) -> Self
pub const fn new( id: BufferId, lines: Vec<String>, cursor: Cursor, file_path: Option<String>, modified: bool, ) -> Self
Create a snapshot from individual components.
This is useful for testing or when constructing a snapshot without a buffer.
Sourcepub const fn line_count(&self) -> usize
pub const fn line_count(&self) -> usize
Get the number of lines.
Sourcepub fn line(&self, idx: usize) -> Option<&str>
pub fn line(&self, idx: usize) -> Option<&str>
Get a specific line by index.
Returns None if index is out of bounds.
Sourcepub fn text_in_range(&self, start: Position, end: Position) -> String
pub fn text_in_range(&self, start: Position, end: Position) -> String
Extract text within a range.
Returns the text between start and end positions.
Positions are clamped to valid bounds.
Sourcepub fn is_valid_position(&self, pos: Position) -> bool
pub fn is_valid_position(&self, pos: Position) -> bool
Check if a position is valid within this snapshot.
Trait Implementations§
Source§impl Clone for BufferSnapshot
impl Clone for BufferSnapshot
Source§fn clone(&self) -> BufferSnapshot
fn clone(&self) -> BufferSnapshot
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more