Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
git_ui: Show file counts in git panel section headers (#65028)
Mansoor Ahmedc9daddfa0ac4
diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rsindex f04282446f2..ed59a09733f 100644--- a/crates/git_ui/src/git_panel.rs+++ b/crates/git_ui/src/git_panel.rs@@ -1150,6 +1150,7 @@ pub struct GitPanel {mark_range_gesture: Option<MarkRangeGesture>,tracked_count: usize,tracked_staged_count: usize,+ section_file_counts: HashMap<Section, usize>,update_visible_entries_task: Task<()>,reopen_commit_buffer_task: Task<()>,pub(crate) workspace: WeakEntity<Workspace>,@@ -1465,6 +1466,7 @@ impl GitPanel {mark_range_gesture: None,tracked_count: 0,tracked_staged_count: 0,+ section_file_counts: HashMap::default(),update_visible_entries_task: Task::ready(()),reopen_commit_buffer_task: Task::ready(()),show_placeholders: false,@@ -5459,6 +5461,7 @@ impl GitPanel {self.new_staged_count = 0;self.tracked_staged_count = 0;self.entry_count = 0;+ self.section_file_counts.clear();self.max_width_item_index = None;let settings = GitPanelSettings::get_global(cx);@@ -5671,6 +5674,11 @@ impl GitPanel {let has_any_section_entries = section_entries.iter().any(|(_, entries)| !entries.is_empty());+ self.section_file_counts.extend(+ section_entries+ .iter()+ .map(|(section, entries)| (*section, entries.len())),+ );let show_when_empty = |section: Section| {group_by_staging_state&& has_any_section_entries@@ -8123,6 +8131,11 @@ impl GitPanel {.entries.get(ix + 1).is_some_and(GitListEntry::is_selectable);+ let file_count = self+ .section_file_counts+ .get(§ion)+ .copied()+ .unwrap_or_default();h_flex().id(id)@@ -8139,6 +8152,7 @@ impl GitPanel {.border_r_2().child(h_flex()+ .flex_1().gap_1().child(Icon::new(if is_collapsed {@@ -8155,6 +8169,9 @@ impl GitPanel {.size(LabelSize::Small),),)+ .when(file_count > 0, |this| {+ this.child(Chip::new(file_count.to_string()).label_color(Color::Muted))+ }).child(if section_is_empty {gpui::Empty.into_any_element()} else {@@ -11224,6 +11241,9 @@ mod tests {deleted: 2,}));+ assert_eq!(panel.section_file_counts.get(&Section::Conflict), Some(&1));+ assert_eq!(panel.section_file_counts.get(&Section::Staged), Some(&3));+ assert_eq!(panel.section_file_counts.get(&Section::Unstaged), Some(&4));panel.entries.clone()});@@ -12114,6 +12134,11 @@ mod tests {cx.executor().advance_clock(2 * UPDATE_DEBOUNCE);handle.await;+ panel.read_with(cx, |panel, _| {+ assert_eq!(panel.section_file_counts.get(&Section::Conflict), Some(&1));+ assert_eq!(panel.section_file_counts.get(&Section::Tracked), Some(&3));+ assert_eq!(panel.section_file_counts.get(&Section::New), Some(&3));+ });let entries = panel.read_with(cx, |panel, _| panel.entries.clone());#[rustfmt::skip]pretty_assertions::assert_matches!(