From 88e8f7af6861f56edddccd9a87790602043c48fb Mon Sep 17 00:00:00 2001 From: Julia Ryan Date: Thu, 28 Aug 2025 14:07:02 -0700 Subject: [PATCH] Activate preview for initially selected item (#37112) @JosephTLyons pointed out that it's a bit weird that we only show a preview for items selected after the initial one, so this does it for that too. It makes tab switching feel even faster! Release Notes: - N/A Co-authored-by: David Kleingeld --- crates/tab_switcher/src/tab_switcher.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/tab_switcher/src/tab_switcher.rs b/crates/tab_switcher/src/tab_switcher.rs index 5f60bc03f2a74f06680007d26edf63168b9c256e..241642115a3025aba13fe1aa8788e2c382b24693 100644 --- a/crates/tab_switcher/src/tab_switcher.rs +++ b/crates/tab_switcher/src/tab_switcher.rs @@ -360,7 +360,12 @@ impl TabSwitcherDelegate { .detach(); } - fn update_all_pane_matches(&mut self, query: String, window: &mut Window, cx: &mut App) { + fn update_all_pane_matches( + &mut self, + query: String, + window: &mut Window, + cx: &mut Context>, + ) { let Some(workspace) = self.workspace.upgrade() else { return; }; @@ -418,7 +423,7 @@ impl TabSwitcherDelegate { let selected_item_id = self.selected_item_id(); self.matches = matches; - self.selected_index = self.compute_selected_index(selected_item_id); + self.selected_index = self.compute_selected_index(selected_item_id, window, cx); } fn update_matches( @@ -477,7 +482,7 @@ impl TabSwitcherDelegate { a_score.cmp(&b_score) }); - self.selected_index = self.compute_selected_index(selected_item_id); + self.selected_index = self.compute_selected_index(selected_item_id, window, cx); } fn selected_item_id(&self) -> Option { @@ -486,7 +491,12 @@ impl TabSwitcherDelegate { .map(|tab_match| tab_match.item.item_id()) } - fn compute_selected_index(&mut self, prev_selected_item_id: Option) -> usize { + fn compute_selected_index( + &mut self, + prev_selected_item_id: Option, + window: &mut Window, + cx: &mut Context>, + ) -> usize { if self.matches.is_empty() { return 0; } @@ -508,8 +518,10 @@ impl TabSwitcherDelegate { return self.matches.len() - 1; } + // This only runs when initially opening the picker + // Index 0 is already active, so don't preselect it for switching. if self.matches.len() > 1 { - // Index 0 is active, so don't preselect it for switching. + self.set_selected_index(1, window, cx); return 1; }