feat: redesign commit diff view
Rust / build (macos-latest, stable) (push) Canceled after 0s
Rust / build (ubuntu-latest, stable) (push) Canceled after 0s
Rust / build (windows-latest, stable) (push) Canceled after 0s

This commit is contained in:
2026-11-21 20:41:50 +07:00
parent 7691a5a7e1
commit 81a46abbe5
22 changed files with 1080 additions and 265 deletions
+92
View File
@@ -181,3 +181,95 @@ impl RenderOnce for Badge {
})
}
}
/// A pill pairing a green additions segment with a red deletions segment.
#[derive(IntoElement)]
#[must_use]
pub struct GroupedBadge {
id: ElementId,
insertions: usize,
deletions: usize,
style: StyleRefinement,
}
impl GroupedBadge {
/// Creates a grouped badge from insertion and deletion counts.
pub fn new<I>(id: I, insertions: usize, deletions: usize) -> Self
where
I: Into<ElementId>,
{
Self {
id: id.into(),
insertions,
deletions,
style: StyleRefinement::default(),
}
}
}
impl gpui::Styled for GroupedBadge {
fn style(&mut self) -> &mut gpui::StyleRefinement {
&mut self.style
}
}
impl RenderOnce for GroupedBadge {
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.theme();
let additions = (
theme.ramps.success.base.opacity(0.2),
theme.ramps.success.base,
);
let deletions = (
theme.ramps.destructive.base.opacity(0.2),
theme.ramps.destructive.base,
);
h_flex()
.id(self.id.clone())
.debug_selector({
let id = self.id.clone();
move || format!("{id}")
})
.flex_none()
.text_xs()
.font_medium()
.when(self.insertions > 0, |group| {
group.child(
h_flex()
.justify_center()
.h_5()
.px_1p5()
.bg(additions.0)
.text_color(additions.1)
.debug_selector({
let id = self.id.clone();
move || format!("{id}-additions")
})
.when(self.deletions == 0, |segment| segment.rounded_full())
.when(self.deletions > 0, |segment| segment.rounded_l_full())
.child(SharedString::from(format!("+{}", self.insertions))),
)
})
.when(self.deletions > 0, |group| {
group.child(
h_flex()
.justify_center()
.h_5()
.px_1p5()
.bg(deletions.0)
.text_color(deletions.1)
.debug_selector({
let id = self.id.clone();
move || format!("{id}-deletions")
})
.when(self.insertions == 0, |segment| segment.rounded_full())
.when(self.insertions > 0, |segment| segment.rounded_r_full())
.child(SharedString::from(format!("-{}", self.deletions))),
)
})
.refine_style(&self.style)
}
}
+2 -1
View File
@@ -326,6 +326,8 @@ impl RenderOnce for Button {
h_flex()
.id(self.id.clone())
.refine_style(&self.style)
.flex_shrink_0()
.when_some(self.debug_selector, |button, selector| {
button.debug_selector(move || selector())
})
@@ -351,7 +353,6 @@ impl RenderOnce for Button {
.border_color(border)
.when_some(background, |button, background| button.bg(background))
.text_color(foreground)
.refine_style(&self.style)
.when_some(a11y_label, |button, label| button.aria_label(label))
.child(
h_flex()
+6 -2
View File
@@ -133,7 +133,7 @@ impl RenderOnce for Switch {
h_flex()
.id(self.id)
.gap_2()
.gap_1()
.control_text(self.size)
.refine_style(&self.style)
.role(Role::Switch)
@@ -179,7 +179,11 @@ impl RenderOnce for Switch {
.left(inset)
.switch_knob(self.size)
.rounded(theme.radius.full)
.bg(colors.primary_foreground)
.bg(if self.checked {
colors.primary_foreground
} else {
colors.muted_foreground
})
.with_spring("switch-thumb", anim, move |thumb, offset| {
thumb.left(inset + offset)
}),