From d2f4d37af8bb59690eaaec9221dd9e28ac45a767 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 15 Nov 2021 13:36:40 -0800 Subject: [PATCH] Get BlockMap randomized test passing w/o soft wraps Co-Authored-By: Nathan Sobo --- crates/editor/src/display_map/block_map.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/editor/src/display_map/block_map.rs b/crates/editor/src/display_map/block_map.rs index 615cf0d94b..68f0117192 100644 --- a/crates/editor/src/display_map/block_map.rs +++ b/crates/editor/src/display_map/block_map.rs @@ -133,6 +133,10 @@ impl BlockMap { } fn apply_edits(&self, wrap_snapshot: &WrapSnapshot, edits: Vec, cx: &AppContext) { + if edits.is_empty() { + return; + } + let buffer = self.buffer.read(cx); let mut transforms = self.transforms.lock(); let mut new_transforms = SumTree::new(); @@ -173,8 +177,6 @@ impl BlockMap { break; } } - old_end = old_end.min(old_max_point); - new_end = new_end.min(new_max_point); // Find the blocks within this edited region. // @@ -192,7 +194,7 @@ impl BlockMap { let end_block_ix = if new_end.row() > wrap_snapshot.max_point().row() { self.blocks.len() } else { - let end_anchor = buffer.anchor_before(Point::new(new_end.row() + 1, 0)); + let end_anchor = buffer.anchor_before(Point::new(new_end.row(), 0)); match self.blocks[start_block_ix..].binary_search_by(|probe| { probe .position @@ -236,6 +238,9 @@ impl BlockMap { new_transforms.push(Transform::block(block.clone()), &()); } + old_end = old_end.min(old_max_point); + new_end = new_end.min(new_max_point); + // Insert an isomorphic transform after the final block. let extent_after_last_block = new_end.0 - new_transforms.summary().input; if !extent_after_last_block.is_zero() {