editor: Fix bracket colorization discoloring pure deletion diff hunks (#49618)
Release Notes: - N/A *or* Added/Fixed/Improved ... Co-authored by: Cole Miller <cole@zed.dev>
This commit is contained in:
1 parent
8361cc3620
commit
bf772b1b60
3 files changed
+17
-11
No files matched your search
@@ -2334,11 +2334,7 @@ impl AcpThread {
|
||||
text_diff(old_text.as_str(), &content)
|
||||
.into_iter()
|
||||
.map(|(range, replacement)| {
|
||||
(
|
||||
snapshot.anchor_after(range.start)
|
||||
..snapshot.anchor_before(range.end),
|
||||
replacement,
|
||||
)
|
||||
(snapshot.anchor_range_between(range), replacement)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
|
||||
@@ -64,12 +64,10 @@ impl Editor {
|
||||
.filter_map(|pair| {
|
||||
let color_index = pair.color_index?;
|
||||
|
||||
let buffer_open_range = buffer_snapshot
|
||||
.anchor_before(pair.open_range.start)
|
||||
..buffer_snapshot.anchor_after(pair.open_range.end);
|
||||
let buffer_close_range = buffer_snapshot
|
||||
.anchor_before(pair.close_range.start)
|
||||
..buffer_snapshot.anchor_after(pair.close_range.end);
|
||||
let buffer_open_range =
|
||||
buffer_snapshot.anchor_range_around(pair.open_range);
|
||||
let buffer_close_range =
|
||||
buffer_snapshot.anchor_range_around(pair.close_range);
|
||||
let [
|
||||
buffer_open_range_start,
|
||||
buffer_open_range_end,
|
||||
|
||||
@@ -2401,10 +2401,22 @@ impl BufferSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an anchor range for the given input position range that is anchored to the text inbetween.
|
||||
pub fn anchor_range_around<T: ToOffset>(&self, position: Range<T>) -> Range<Anchor> {
|
||||
self.anchor_before(position.start)..self.anchor_after(position.end)
|
||||
}
|
||||
|
||||
/// Returns an anchor range for the given input position range that is anchored to the text before the start position and after the end position.
|
||||
pub fn anchor_range_between<T: ToOffset>(&self, position: Range<T>) -> Range<Anchor> {
|
||||
self.anchor_before(position.start)..self.anchor_after(position.end)
|
||||
}
|
||||
|
||||
/// Returns an anchor for the given input position that is anchored to the text before the position.
|
||||
pub fn anchor_before<T: ToOffset>(&self, position: T) -> Anchor {
|
||||
self.anchor_at(position, Bias::Left)
|
||||
}
|
||||
|
||||
/// Returns an anchor for the given input position that is anchored to the text after the position.
|
||||
pub fn anchor_after<T: ToOffset>(&self, position: T) -> Anchor {
|
||||
self.anchor_at(position, Bias::Right)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user