Skip to content

Commit

Permalink
add c-d to file_picker for filter path starts_with cwd
Browse files Browse the repository at this point in the history
add c-f to file_picker for filter path starts_with current file's dir
  • Loading branch information
cossonleo committed Jan 24, 2022
1 parent a4fffae commit 35651f4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
9 changes: 9 additions & 0 deletions book/src/keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 30 additions & 1 deletion helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,37 @@ impl<T: 'static> Component for FilePicker<T> {
}

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<Position>, CursorKind) {
Expand Down

0 comments on commit 35651f4

Please sign in to comment.