Propagate wrap edits to block map when folding / unfolding

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2021-11-15 14:17:48 -08:00
parent d2f4d37af8
commit b4bc7906d2
2 changed files with 16 additions and 8 deletions

View file

@ -80,12 +80,16 @@ impl DisplayMap {
) {
let (mut fold_map, snapshot, edits) = self.fold_map.write(cx);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits);
self.wrap_map
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.sync(&snapshot, edits, cx);
let (snapshot, edits) = fold_map.fold(ranges, cx);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits);
self.wrap_map
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.sync(&snapshot, edits, cx);
}
pub fn unfold<T: ToOffset>(
@ -95,12 +99,16 @@ impl DisplayMap {
) {
let (mut fold_map, snapshot, edits) = self.fold_map.write(cx);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits);
self.wrap_map
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.sync(&snapshot, edits, cx);
let (snapshot, edits) = fold_map.unfold(ranges, cx);
let (snapshot, edits) = self.tab_map.sync(snapshot, edits);
self.wrap_map
let (snapshot, edits) = self
.wrap_map
.update(cx, |map, cx| map.sync(snapshot, edits, cx));
self.block_map.sync(&snapshot, edits, cx);
}
pub fn insert_blocks<P, T>(

View file

@ -113,7 +113,7 @@ impl BlockMap {
edits: Vec<WrapEdit>,
cx: &AppContext,
) -> BlockSnapshot {
self.apply_edits(&wrap_snapshot, edits, cx);
self.sync(&wrap_snapshot, edits, cx);
*self.wrap_snapshot.lock() = wrap_snapshot.clone();
BlockSnapshot {
wrap_snapshot,
@ -127,12 +127,12 @@ impl BlockMap {
edits: Vec<WrapEdit>,
cx: &AppContext,
) -> BlockMapWriter {
self.apply_edits(&wrap_snapshot, edits, cx);
self.sync(&wrap_snapshot, edits, cx);
*self.wrap_snapshot.lock() = wrap_snapshot;
BlockMapWriter(self)
}
fn apply_edits(&self, wrap_snapshot: &WrapSnapshot, edits: Vec<WrapEdit>, cx: &AppContext) {
pub fn sync(&self, wrap_snapshot: &WrapSnapshot, edits: Vec<WrapEdit>, cx: &AppContext) {
if edits.is_empty() {
return;
}
@ -356,7 +356,7 @@ impl<'a> BlockMapWriter<'a> {
}
}
self.0.apply_edits(&*self.0.wrap_snapshot.lock(), edits, cx);
self.0.sync(&*self.0.wrap_snapshot.lock(), edits, cx);
ids
}