From 4f8f3bd4c4c1c1171a2dabdca5fd6b3ebf2ddfa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Tue, 6 Oct 2026 22:55:43 -0400 Subject: [PATCH] =?UTF-8?q?Git=20=C2=B7=20ChangesList:=20line=20counts=20a?= =?UTF-8?q?re=20optional,=20so=20binary=20files=20and=20folders=20show=20n?= =?UTF-8?q?one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/gallery/pages/git/work.rs | 3 +-- src/git/changes.rs | 10 +++++----- src/git/tests.rs | 8 +++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/gallery/pages/git/work.rs b/examples/gallery/pages/git/work.rs index caa01b9..13a5acc 100644 --- a/examples/gallery/pages/git/work.rs +++ b/examples/gallery/pages/git/work.rs @@ -19,8 +19,7 @@ fn changed(path: &str, status: GitStatus, added: usize, removed: usize) -> Chang Changed { path: path.to_string().into(), status, - added, - removed, + lines: Some((added, removed)), } } diff --git a/src/git/changes.rs b/src/git/changes.rs index f8e5416..e37ed19 100644 --- a/src/git/changes.rs +++ b/src/git/changes.rs @@ -21,8 +21,8 @@ use crate::{ pub struct Changed { pub path: SharedString, pub status: GitStatus, - pub added: usize, - pub removed: usize, + /// Added and removed; None when not counted, as for a binary file or a folder. + pub lines: Option<(usize, usize)>, } /// What a changes list asks for a file. @@ -234,10 +234,10 @@ impl ChangesList { }, ), ) - .child( + .children(file.lines.map(|(added, removed)| { tabular(div().flex_none().text_color(colors.fg_subtle)) - .child(format!("+{} −{}", file.added, file.removed)), - ) + .child(format!("+{added} −{removed}")) + })) .into_any_element() } diff --git a/src/git/tests.rs b/src/git/tests.rs index f12dd96..f8fa8f3 100644 --- a/src/git/tests.rs +++ b/src/git/tests.rs @@ -85,8 +85,7 @@ impl Render for Sorted { let file = |path: &str, status| super::Changed { path: path.to_string().into(), status, - added: 1, - removed: 0, + lines: Some((1, 0)), }; div().w(px(420.0)).child( super::ChangesList::new( @@ -96,7 +95,10 @@ impl Render for Sorted { ) .conflicted([file("c.rs", GitStatus::Conflicted)]) .untracked([file("d.rs", GitStatus::Untracked)]) - .ignored([file("target/", GitStatus::Untracked)]), + .ignored([super::Changed { + lines: None, + ..file("target/", GitStatus::Untracked) + }]), ) } }