Fix next/prev shortcuts handling in the File Finder (#9785)
This PR fixes the unexpected File Finder behaviour described in https://github.com/zed-industries/zed/pull/8782#issuecomment-2018551041 Any change of the modifier keys except for the release of the initial modifier keys now prevents opening the selected file. Release Notes: - N/A
This commit is contained in:
parent
bdea804c48
commit
1b4c82dc2c
5 changed files with 137 additions and 8 deletions
|
@ -25,7 +25,7 @@ use ui::{prelude::*, HighlightedLabel, ListItem, ListItemSpacing};
|
|||
use util::{paths::PathLikeWithPosition, post_inc, ResultExt};
|
||||
use workspace::{ModalView, Workspace};
|
||||
|
||||
actions!(file_finder, [Toggle]);
|
||||
actions!(file_finder, [Toggle, SelectPrev]);
|
||||
|
||||
impl ModalView for FileFinder {}
|
||||
|
||||
|
@ -47,9 +47,10 @@ impl FileFinder {
|
|||
};
|
||||
|
||||
file_finder.update(cx, |file_finder, cx| {
|
||||
file_finder
|
||||
.picker
|
||||
.update(cx, |picker, cx| picker.cycle_selection(cx))
|
||||
file_finder.init_modifiers = Some(cx.modifiers());
|
||||
file_finder.picker.update(cx, |picker, cx| {
|
||||
picker.cycle_selection(cx);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -105,7 +106,7 @@ impl FileFinder {
|
|||
event: &ModifiersChangedEvent,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
let Some(init_modifiers) = self.init_modifiers else {
|
||||
let Some(init_modifiers) = self.init_modifiers.take() else {
|
||||
return;
|
||||
};
|
||||
if self.picker.read(cx).delegate.has_changed_selected_index {
|
||||
|
@ -115,6 +116,11 @@ impl FileFinder {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_select_prev(&mut self, _: &SelectPrev, cx: &mut ViewContext<Self>) {
|
||||
self.init_modifiers = Some(cx.modifiers());
|
||||
cx.dispatch_action(Box::new(menu::SelectPrev));
|
||||
}
|
||||
}
|
||||
|
||||
impl EventEmitter<DismissEvent> for FileFinder {}
|
||||
|
@ -131,6 +137,7 @@ impl Render for FileFinder {
|
|||
.key_context("FileFinder")
|
||||
.w(rems(34.))
|
||||
.on_modifiers_changed(cx.listener(Self::handle_modifiers_changed))
|
||||
.on_action(cx.listener(Self::handle_select_prev))
|
||||
.child(self.picker.clone())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue