Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add c-f c-d keymap to file_picker to filter option. #1405

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason these can't just go into the Picker section's table?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shortcut only works on FilePicker.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you telling me that these shortcuts in the File Picker section work outside of the file picker?

helix/book/src/keymap.md

Lines 297 to 309 in ddbf036

# Picker
Keys to use within picker. Remapping currently not supported.
| Key | Description |
| ----- | ------------- |
| `Up`, `Ctrl-k`, `Ctrl-p` | Previous entry |
| `Down`, `Ctrl-j`, `Ctrl-n` | Next entry |
| `Ctrl-space` | Filter options |
| `Enter` | Open selected |
| `Ctrl-s` | Open horizontally |
| `Ctrl-v` | Open vertically |
| `Escape`, `Ctrl-c` | Close picker |

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, those shortcuts works on any picker and this is specific to file picker.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhhh, I see, sorry for my confusion. In that case, could we update the title to just "File picker", and update the wording in the sentence just below here to say that these are specific to the file picker?


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
33 changes: 31 additions & 2 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,38 @@ impl<T: 'static> Component for FilePicker<T> {
}
}

fn handle_event(&mut self, event: Event, ctx: &mut Context) -> EventResult {
fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
let key_event = match event {
Event::Key(event) => event,
_ => return self.picker.handle_event(event, cx),
};

let mut filter = |d| {
self.picker.options.retain(|item| {
(self.file_fn)(cx.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!('l') => {
if let Some(cwd) = doc!(cx.editor).path().and_then(|p| p.parent()) {
filter(cwd);
}
EventResult::Consumed(None)
}
_ => self.picker.handle_event(event, cx),
}
// TODO: keybinds for scrolling preview
self.picker.handle_event(event, ctx)
}

fn cursor(&self, area: Rect, ctx: &Editor) -> (Option<Position>, CursorKind) {
Expand Down