@@ -838,6 +838,27 @@ impl Buffer {
838838 self . snapshot
839839 }
840840
841+ /// Returns a preview snapshot derived by applying one synthetic local-branch edit.
842+ ///
843+ /// This is intended for one-off preview workflows like syntax interpolation, not for
844+ /// repeatedly mutating or composing synthetic snapshot histories.
845+ pub fn snapshot_with_edits < I , S , T > ( & self , edits : I ) -> BufferSnapshot
846+ where
847+ I : IntoIterator < Item = ( Range < S > , T ) > ,
848+ S : ToOffset ,
849+ T : Into < Arc < str > > ,
850+ {
851+ let mut snapshot = self . snapshot . clone ( ) ;
852+ let timestamp = Lamport :: new ( ReplicaId :: LOCAL_BRANCH ) . tick ( ) ;
853+ let edits: Vec < _ > = edits
854+ . into_iter ( )
855+ . map ( |( range, new_text) | ( range. to_offset ( & snapshot) , new_text. into ( ) ) )
856+ . collect ( ) ;
857+ snapshot. apply_edit_internal ( edits, timestamp) ;
858+ snapshot. version . observe ( timestamp) ;
859+ snapshot
860+ }
861+
841862 pub fn replica_id ( & self ) -> ReplicaId {
842863 self . lamport_clock . replica_id
843864 }
@@ -1854,24 +1875,6 @@ impl Deref for Buffer {
18541875}
18551876
18561877impl BufferSnapshot {
1857- /// Edits the snapshot in place, applying the given edits to the text content.
1858- /// This is useful for creating a modified snapshot without needing a full Buffer.
1859- pub fn edit < I , S , T > ( & mut self , edits : I )
1860- where
1861- I : IntoIterator < Item = ( Range < S > , T ) > ,
1862- S : ToOffset ,
1863- T : Into < Arc < str > > ,
1864- {
1865- let mut lamport_clock = clock:: Lamport :: new ( ReplicaId :: LOCAL_BRANCH ) ;
1866- let timestamp = lamport_clock. tick ( ) ;
1867- let edits: Vec < _ > = edits
1868- . into_iter ( )
1869- . map ( |( range, new_text) | ( range. to_offset ( self ) , new_text. into ( ) ) )
1870- . collect ( ) ;
1871- self . apply_edit_internal ( edits, timestamp) ;
1872- self . version . observe ( timestamp) ;
1873- }
1874-
18751878 fn apply_edit_internal (
18761879 & mut self ,
18771880 edits : Vec < ( Range < usize > , Arc < str > ) > ,
0 commit comments