diff --git a/book/src/keymap.md b/book/src/keymap.md index 905ec48fa8d0e..c1748175aaa62 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -311,6 +311,15 @@ Keys to use within picker. Remapping currently not supported. | `Ctrl-v` | Open vertically | | `Escape`, `Ctrl-c` | Close picker | +## File Picker extra keymap + +Keys to use within picker. Remapping currently not supported. + +| Key | Description | +| ----- | ------------- | +| `Ctrl-f` | Retain current doc dir's subpath | +| `Ctrl-a` | Retain cwd's subpath | + # Prompt Keys to use within prompt, Remapping currently not supported. diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 945e14bb7e54b..d90ed2e5b670a 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -253,8 +253,37 @@ impl Component for FilePicker { } fn handle_event(&mut self, event: Event, ctx: &mut Context) -> EventResult { + let key_event = match event { + Event::Key(event) => event, + _ => return self.picker.handle_event(event, ctx), + }; + + let mut filter = |d| { + self.picker.options.retain(|item| { + (self.file_fn)(ctx.editor, item) + .map(|fl| fl.0.starts_with(d)) + .unwrap_or(false) + }); + self.picker.filters.clear(); + self.picker.score(); + }; + + match key_event.into() { + ctrl!('a') => { + if let Ok(cwd) = std::env::current_dir() { + filter(cwd.as_path()); + } + EventResult::Consumed(None) + } + ctrl!('f') => { + if let Some(cwd) = doc!(ctx.editor).path().and_then(|p| p.parent()) { + filter(cwd); + } + EventResult::Consumed(None) + } + _ => self.picker.handle_event(event, ctx), + } // TODO: keybinds for scrolling preview - self.picker.handle_event(event, ctx) } fn cursor(&self, area: Rect, ctx: &Editor) -> (Option, CursorKind) {