diff --git a/Cargo.lock b/Cargo.lock index 142ec58ed40097529cfcebb4853ae3956eee47c0..a8f241c0291895d23fff32d0f3617ad607bd5213 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7303,6 +7303,7 @@ dependencies = [ "serde", "serde_json", "settings", + "smallvec", "smol", "strum 0.27.2", "telemetry", diff --git a/crates/git_ui/Cargo.toml b/crates/git_ui/Cargo.toml index b9bd31fb8307b8105badc95477daf54f4001e9e9..d877176742210e16a6b22d279259df976a26679a 100644 --- a/crates/git_ui/Cargo.toml +++ b/crates/git_ui/Cargo.toml @@ -51,6 +51,7 @@ schemars.workspace = true serde.workspace = true serde_json.workspace = true settings.workspace = true +smallvec.workspace = true smol.workspace = true strum.workspace = true telemetry.workspace = true diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs index a16620407f8f0823ba77320e3da23cb81654c6ec..24278420a16d23cfa345bc6ea58138c7f1aa29db 100644 --- a/crates/git_ui/src/git_panel.rs +++ b/crates/git_ui/src/git_panel.rs @@ -57,6 +57,7 @@ use project::{ use prompt_store::{BuiltInPrompt, PromptId, PromptStore, RULES_FILE_NAMES}; use serde::{Deserialize, Serialize}; use settings::{Settings, SettingsStore, StatusStyle}; +use smallvec::SmallVec; use std::future::Future; use std::ops::Range; use std::path::Path; @@ -290,6 +291,15 @@ impl GitListEntry { _ => None, } } + + /// Returns the tree indentation depth for this entry. + fn depth(&self) -> usize { + match self { + GitListEntry::Directory(dir) => dir.depth, + GitListEntry::TreeStatus(status) => status.depth, + _ => 0, + } + } } enum GitPanelViewMode { @@ -3806,6 +3816,24 @@ impl GitPanel { self.has_staged_changes() } + /// Computes tree indentation depths for visible entries in the given range. + /// Used by indent guides to render vertical connector lines in tree view. + fn compute_visible_depths(&self, range: Range) -> SmallVec<[usize; 64]> { + let GitPanelViewMode::Tree(state) = &self.view_mode else { + return SmallVec::new(); + }; + + range + .map(|ix| { + state + .logical_indices + .get(ix) + .and_then(|&entry_ix| self.entries.get(entry_ix)) + .map_or(0, |entry| entry.depth()) + }) + .collect() + } + fn status_width_estimate( tree_view: bool, entry: &GitStatusEntry, @@ -4683,15 +4711,7 @@ impl GitPanel { .with_compute_indents_fn( cx.entity(), |this, range, _window, _cx| { - range - .map(|ix| match this.entries.get(ix) { - Some(GitListEntry::Directory(dir)) => dir.depth, - Some(GitListEntry::TreeStatus(status)) => { - status.depth - } - _ => 0, - }) - .collect() + this.compute_visible_depths(range) }, ) .with_render_fn(cx.entity(), |_, params, _, _| {