Cycle file finder entries on cmd-p

This commit is contained in:
Kirill Bulatov 2023-09-27 23:02:31 +02:00
parent 81a107f503
commit 541dd994a9

View file

@ -81,13 +81,27 @@ impl FoundPath {
actions!(file_finder, [Toggle]); actions!(file_finder, [Toggle]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.add_action(toggle_file_finder); cx.add_action(toggle_or_cycle_file_finder);
FileFinder::init(cx); FileFinder::init(cx);
} }
const MAX_RECENT_SELECTIONS: usize = 20; const MAX_RECENT_SELECTIONS: usize = 20;
fn toggle_file_finder(workspace: &mut Workspace, _: &Toggle, cx: &mut ViewContext<Workspace>) { fn toggle_or_cycle_file_finder(
workspace: &mut Workspace,
_: &Toggle,
cx: &mut ViewContext<Workspace>,
) {
match workspace.modal::<FileFinder>() {
Some(file_finder) => file_finder.update(cx, |file_finder, cx| {
let current_index = file_finder.delegate().selected_index();
file_finder.select_next(&menu::SelectNext, cx);
let new_index = file_finder.delegate().selected_index();
if current_index == new_index {
file_finder.select_first(&menu::SelectFirst, cx);
}
}),
None => {
workspace.toggle_modal(cx, |workspace, cx| { workspace.toggle_modal(cx, |workspace, cx| {
let project = workspace.project().read(cx); let project = workspace.project().read(cx);
@ -142,6 +156,8 @@ fn toggle_file_finder(workspace: &mut Workspace, _: &Toggle, cx: &mut ViewContex
finder finder
}); });
} }
}
}
pub enum Event { pub enum Event {
Selected(ProjectPath), Selected(ProjectPath),