From c0ffeeef2c96caa89e5f8dc90e0f9fcec1718336 Mon Sep 17 00:00:00 2001 From: Hendrik Sollich Date: Fri, 1 Aug 2025 20:29:50 +0200 Subject: [PATCH] Preserve selected item when refiltering project symbols Add manual symbol selection in project symbols picker When navigating to a symbol using arrow keys, store the selected symbol so we can restore the same selection after re-filtering. --- crates/project_symbols/src/project_symbols.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/project_symbols/src/project_symbols.rs b/crates/project_symbols/src/project_symbols.rs index 47aed8f470..f74bbbf2e0 100644 --- a/crates/project_symbols/src/project_symbols.rs +++ b/crates/project_symbols/src/project_symbols.rs @@ -44,6 +44,7 @@ pub struct ProjectSymbolsDelegate { external_match_candidates: Vec, show_worktree_root_name: bool, matches: Vec, + manually_selected: Option, } impl ProjectSymbolsDelegate { @@ -57,6 +58,7 @@ impl ProjectSymbolsDelegate { external_match_candidates: Default::default(), matches: Default::default(), show_worktree_root_name: false, + manually_selected: None, } } @@ -99,6 +101,18 @@ impl ProjectSymbolsDelegate { } self.matches = matches; + + // Preserve manually selected item if it exists + if let Some(manually_selected) = &self.manually_selected { + if let Some(index) = self.matches.iter().position(|mat| { + let symbol = &self.symbols[mat.candidate_id]; + symbol.path == manually_selected.path && symbol.range == manually_selected.range + }) { + self.set_selected_index(index, window, cx); + return; + } + } + self.set_selected_index(0, window, cx); } } @@ -168,6 +182,11 @@ impl PickerDelegate for ProjectSymbolsDelegate { _cx: &mut Context>, ) { self.selected_match_index = ix; + + // Store the manually selected symbol + if let Some(mat) = self.matches.get(ix) { + self.manually_selected = Some(self.symbols[mat.candidate_id].clone()); + } } fn update_matches(