diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rs index 433abfb12e206bd1d289d9c5b418955917f22744..fa70686ee35634d2f3e6081804f69629d57823d0 100644 --- a/crates/acp_thread/src/acp_thread.rs +++ b/crates/acp_thread/src/acp_thread.rs @@ -2315,11 +2315,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::>() }) diff --git a/crates/editor/src/bracket_colorization.rs b/crates/editor/src/bracket_colorization.rs index 303bdbfed794f0bf2c301462b354771ed575b8e5..3710016b51f4a89a3f99feea5a1699c7c477cc11 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 506116e7df768bfecd1ab2866108e69147270eb6..91767d99841b721d529de45229c1b067a563cf72 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(&self, position: Range) -> Range { + 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(&self, position: Range) -> Range { + 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(&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(&self, position: T) -> Anchor { self.anchor_at(position, Bias::Right) }