From 14eab4e94fae61b860bba70c8e74ba979bbf53c4 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 3 Jul 2023 19:22:43 +0200 Subject: [PATCH] branch list: dismiss correct window on PickerEvent. Query proper window --- crates/collab_ui/src/branch_list.rs | 18 ++++++++---------- crates/collab_ui/src/collab_titlebar_item.rs | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/crates/collab_ui/src/branch_list.rs b/crates/collab_ui/src/branch_list.rs index 8c06326780..e0f85aa65a 100644 --- a/crates/collab_ui/src/branch_list.rs +++ b/crates/collab_ui/src/branch_list.rs @@ -60,24 +60,24 @@ impl PickerDelegate for BranchListDelegate { .read_with(&mut cx, |view, cx| { let delegate = view.delegate(); let project = delegate.workspace.read(cx).project().read(&cx); - let mut cwd = project + let mut cwd = + project .visible_worktrees(cx) .next() .unwrap() .read(cx) - .root_entry() - .unwrap() - .path + .abs_path() .to_path_buf(); cwd.push(".git"); let Some(repo) = project.fs().open_repo(&cwd) else {bail!("Project does not have associated git repository.")}; let mut branches = repo .lock() .branches()?; - if query.is_empty() { - const RECENT_BRANCHES_COUNT: usize = 10; + const RECENT_BRANCHES_COUNT: usize = 10; + if query.is_empty() && branches.len() > RECENT_BRANCHES_COUNT { + // Truncate list of recent branches // Do a partial sort to show recent-ish branches first. - branches.select_nth_unstable_by(RECENT_BRANCHES_COUNT, |lhs, rhs| { + branches.select_nth_unstable_by(RECENT_BRANCHES_COUNT - 1, |lhs, rhs| { rhs.unix_timestamp.cmp(&lhs.unix_timestamp) }); branches.truncate(RECENT_BRANCHES_COUNT); @@ -145,9 +145,7 @@ impl PickerDelegate for BranchListDelegate { .next() .ok_or_else(|| anyhow!("There are no visisible worktrees."))? .read(cx) - .root_entry() - .ok_or_else(|| anyhow!("Worktree has no root entry."))? - .path + .abs_path() .to_path_buf(); cwd.push(".git"); let status = project diff --git a/crates/collab_ui/src/collab_titlebar_item.rs b/crates/collab_ui/src/collab_titlebar_item.rs index 1a4869a583..8af3acf7be 100644 --- a/crates/collab_ui/src/collab_titlebar_item.rs +++ b/crates/collab_ui/src/collab_titlebar_item.rs @@ -444,7 +444,7 @@ impl CollabTitlebarItem { cx.subscribe(&view, |this, _, event, cx| { match event { PickerEvent::Dismiss => { - this.contacts_popover = None; + this.branch_popover = None; } }