Refine styling of merge conflicts (#31012)

- Improved colors
- Blank out diff hunk gutter highlights in conflict regions
- Paint conflict marker highlights all the way to the gutter

Release Notes:

- Improved the highlighting of merge conflict markers in editors.

---------

Co-authored-by: Marshall Bowers <git@maxdeviant.com>
Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
Nate Butler 2025-06-09 15:03:19 -04:00 committed by GitHub
parent e4bd115a63
commit 0b7583bae5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 114 additions and 82 deletions

View file

@ -698,7 +698,7 @@ impl EditorActionId {
// type OverrideTextStyle = dyn Fn(&EditorStyle) -> Option<HighlightStyle>;
type BackgroundHighlight = (fn(&ThemeColors) -> Hsla, Arc<[Range<Anchor>]>);
type GutterHighlight = (fn(&App) -> Hsla, Arc<[Range<Anchor>]>);
type GutterHighlight = (fn(&App) -> Hsla, Vec<Range<Anchor>>);
#[derive(Default)]
struct ScrollbarMarkerState {
@ -18377,12 +18377,12 @@ impl Editor {
pub fn highlight_gutter<T: 'static>(
&mut self,
ranges: &[Range<Anchor>],
ranges: impl Into<Vec<Range<Anchor>>>,
color_fetcher: fn(&App) -> Hsla,
cx: &mut Context<Self>,
) {
self.gutter_highlights
.insert(TypeId::of::<T>(), (color_fetcher, Arc::from(ranges)));
.insert(TypeId::of::<T>(), (color_fetcher, ranges.into()));
cx.notify();
}
@ -18394,6 +18394,65 @@ impl Editor {
self.gutter_highlights.remove(&TypeId::of::<T>())
}
pub fn insert_gutter_highlight<T: 'static>(
&mut self,
range: Range<Anchor>,
color_fetcher: fn(&App) -> Hsla,
cx: &mut Context<Self>,
) {
let snapshot = self.buffer().read(cx).snapshot(cx);
let mut highlights = self
.gutter_highlights
.remove(&TypeId::of::<T>())
.map(|(_, highlights)| highlights)
.unwrap_or_default();
let ix = highlights.binary_search_by(|highlight| {
Ordering::Equal
.then_with(|| highlight.start.cmp(&range.start, &snapshot))
.then_with(|| highlight.end.cmp(&range.end, &snapshot))
});
if let Err(ix) = ix {
highlights.insert(ix, range);
}
self.gutter_highlights
.insert(TypeId::of::<T>(), (color_fetcher, highlights));
}
pub fn remove_gutter_highlights<T: 'static>(
&mut self,
ranges_to_remove: Vec<Range<Anchor>>,
cx: &mut Context<Self>,
) {
let snapshot = self.buffer().read(cx).snapshot(cx);
let Some((color_fetcher, mut gutter_highlights)) =
self.gutter_highlights.remove(&TypeId::of::<T>())
else {
return;
};
let mut ranges_to_remove = ranges_to_remove.iter().peekable();
gutter_highlights.retain(|highlight| {
while let Some(range_to_remove) = ranges_to_remove.peek() {
match range_to_remove.end.cmp(&highlight.start, &snapshot) {
Ordering::Less | Ordering::Equal => {
ranges_to_remove.next();
}
Ordering::Greater => {
match range_to_remove.start.cmp(&highlight.end, &snapshot) {
Ordering::Less | Ordering::Equal => {
return false;
}
Ordering::Greater => break,
}
}
}
}
true
});
self.gutter_highlights
.insert(TypeId::of::<T>(), (color_fetcher, gutter_highlights));
}
#[cfg(feature = "test-support")]
pub fn all_text_background_highlights(
&self,