Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

editor: Fix bracket colorization discoloring pure deletion diff hunks (#49618)

Lukas Wirth037add06e4dc
diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rs
index 67698ea5875..c7c598c85e5 100644
--- a/crates/acp_thread/src/acp_thread.rs
+++ b/crates/acp_thread/src/acp_thread.rs
@@ -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<_>>()
})
diff --git a/crates/editor/src/bracket_colorization.rs b/crates/editor/src/bracket_colorization.rs
index 303bdbfed79..3710016b51f 100644
--- a/crates/editor/src/bracket_colorization.rs
+++ b/crates/editor/src/bracket_colorization.rs
@@ -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,
diff --git a/crates/text/src/text.rs b/crates/text/src/text.rs
index 506116e7df7..91767d99841 100644
--- a/crates/text/src/text.rs
+++ b/crates/text/src/text.rs
@@ -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)
}