diff --git a/crates/open_path_prompt/src/open_path_prompt.rs b/crates/open_path_prompt/src/open_path_prompt.rs index 5fa29d453a..cbbebeb6a7 100644 --- a/crates/open_path_prompt/src/open_path_prompt.rs +++ b/crates/open_path_prompt/src/open_path_prompt.rs @@ -577,7 +577,45 @@ impl PickerDelegate for OpenPathDelegate { .ok(); }) } + fn select_child( + &mut self, + _window: &mut Window, + _cx: &mut Context>, + ) -> Option { + let candidate = self.get_entry(self.selected_index)?; + if candidate.path.string.is_empty() || !candidate.is_dir { + return None; + } + let path_style = self.path_style; + match &self.directory_state { + DirectoryState::List { parent_path, .. } + | DirectoryState::Create { parent_path, .. } => Some(format!( + "{}{}{}", + parent_path, + candidate.path.string, + path_style.primary_separator() + )), + DirectoryState::None { .. } => None, + } + } + fn select_parent( + &mut self, + _window: &mut Window, + _cx: &mut Context>, + ) -> Option { + let parent_path = match &self.directory_state { + DirectoryState::List { parent_path, .. } + | DirectoryState::Create { parent_path, .. } => parent_path, + DirectoryState::None { .. } => return None, + }; + if parent_path == &self.prompt_root { + return None; + } + let trimmed = parent_path.trim_end_matches(['/', '\\']); + let (dir, _) = get_dir_and_suffix(trimmed.to_string(), self.path_style); + Some(dir) + } fn confirm_completion( &mut self, query: String, diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index 9f8baac0cb..ad20dfc28c 100644 --- a/crates/picker/src/picker.rs +++ b/crates/picker/src/picker.rs @@ -301,6 +301,27 @@ pub trait PickerDelegate: Sized + 'static { ) -> Option { None } + /// Called when `SelectChild` fires (e.g. shift-right-arrow). Return `Some(query)` + /// to step into the currently selected item (e.g. a directory); the picker + /// will set the query and refresh matches. + fn select_child( + &mut self, + _window: &mut Window, + _cx: &mut Context>, + ) -> Option { + None + } + + /// Called when `SelectParent` fires (e.g. shift-left-arrow). Return `Some(query)` + /// to step back to the parent; the picker will set the query and refresh + /// matches. + fn select_parent( + &mut self, + _window: &mut Window, + _cx: &mut Context>, + ) -> Option { + None + } fn editor_position(&self) -> PickerEditorPosition { PickerEditorPosition::default() @@ -1002,6 +1023,26 @@ impl Picker { cx.propagate() } } + fn select_child(&mut self, _: &menu::SelectChild, window: &mut Window, cx: &mut Context) { + if let Some(new_query) = self.delegate.select_child(window, cx) { + self.set_query(&new_query, window, cx); + } else { + cx.propagate() + } + } + + fn select_parent( + &mut self, + _: &menu::SelectParent, + window: &mut Window, + cx: &mut Context, + ) { + if let Some(new_query) = self.delegate.select_parent(window, cx) { + self.set_query(&new_query, window, cx); + } else { + cx.propagate() + } + } fn set_preview_right( &mut self, diff --git a/crates/picker/src/render.rs b/crates/picker/src/render.rs index 6abdf57113..d9bf085707 100644 --- a/crates/picker/src/render.rs +++ b/crates/picker/src/render.rs @@ -192,6 +192,8 @@ impl Picker { .on_action(cx.listener(Self::editor_move_up)) .on_action(cx.listener(Self::select_first)) .on_action(cx.listener(Self::select_last)) + .on_action(cx.listener(Self::select_child)) + .on_action(cx.listener(Self::select_parent)) .on_action(cx.listener(Self::cancel)) .on_action(cx.listener(Self::confirm)) .on_action(cx.listener(Self::secondary_confirm))