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.

ui: Add thousands separators to diff stats (#56754)

Agus Zubiaga7c1005934041
diff --git a/Cargo.lock b/Cargo.lock
index 742b2879176..7d1d803623e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -19173,6 +19173,7 @@ dependencies = [
"icons",
"itertools 0.14.0",
"menu",
+ "num-format",
"schemars 1.0.4",
"serde",
"smallvec",
diff --git a/crates/ui/Cargo.toml b/crates/ui/Cargo.toml
index 4ae0e6d2e46..97469cae36c 100644
--- a/crates/ui/Cargo.toml
+++ b/crates/ui/Cargo.toml
@@ -21,6 +21,7 @@ gpui_macros.workspace = true
icons.workspace = true
itertools.workspace = true
menu.workspace = true
+num-format.workspace = true
schemars.workspace = true
serde.workspace = true
smallvec.workspace = true
diff --git a/crates/ui/src/components/diff_stat.rs b/crates/ui/src/components/diff_stat.rs
index c2e76b171e7..5fd88903470 100644
--- a/crates/ui/src/components/diff_stat.rs
+++ b/crates/ui/src/components/diff_stat.rs
@@ -1,5 +1,6 @@
use crate::Tooltip;
use crate::prelude::*;
+use num_format::{Locale, ToFormattedString};
#[derive(IntoElement, RegisterComponent)]
pub struct DiffStat {
@@ -35,16 +36,19 @@ impl DiffStat {
impl RenderOnce for DiffStat {
fn render(self, _: &mut Window, _cx: &mut App) -> impl IntoElement {
let tooltip = self.tooltip;
+ let added = self.added.to_formatted_string(&Locale::en);
+ let removed = self.removed.to_formatted_string(&Locale::en);
+
h_flex()
.id(self.id)
.gap_1()
.child(
- Label::new(format!("+\u{2009}{}", self.added))
+ Label::new(format!("+\u{2009}{added}"))
.color(Color::Success)
.size(self.label_size),
)
.child(
- Label::new(format!("\u{2012}\u{2009}{}", self.removed))
+ Label::new(format!("\u{2012}\u{2009}{removed}"))
.color(Color::Error)
.size(self.label_size),
)
@@ -73,7 +77,7 @@ impl Component for DiffStat {
let diff_stat_example = vec![single_example(
"Default",
container()
- .child(DiffStat::new("id", 1, 2))
+ .child(DiffStat::new("id", 1_234, 5_678))
.into_any_element(),
)];