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

[WIP] adding picker mode #868

Closed
wants to merge 1 commit into from

Conversation

VuiMuich
Copy link
Contributor

Attmept to fix #615
(also helpful for #851)

I am trying to add an actual picker mode.

As I am new to this code base (and a project of this scale as well), may I ask for some guidance if I am on the right track?

Some notes on the progress so far:

// "ret" => open,
"C-h" => hsplit,
"C-v" => vsplit,

there obviously needs to be added an actual open command to the 'open as split' binds as well and add the 'filter options'.

Any pointers on how to replace the match key_event {} in impl<T: 'static> Component for Picker<T> {} best?

@archseer
Copy link
Member

I don't think this will work. A picker is a UI component that does not have it's own mode. The commands inside command.rs are all specific to the currently focused buffer and don't operate on selections inside a picker.

What we'd need to do is add a separate keymap that's able to map to picker functions here:

fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
let key_event = match event {
Event::Key(event) => event,
Event::Resize(..) => return EventResult::Consumed(None),
_ => return EventResult::Ignored,
};
let close_fn = EventResult::Consumed(Some(Box::new(|compositor: &mut Compositor| {
// remove the layer
compositor.last_picker = compositor.pop();
})));
match key_event {
KeyEvent {
code: KeyCode::Up, ..
}
| KeyEvent {
code: KeyCode::BackTab,
..
}
| KeyEvent {
code: KeyCode::Char('p'),
modifiers: KeyModifiers::CONTROL,
} => {
self.move_up();
}
KeyEvent {
code: KeyCode::Down,
..
}
| KeyEvent {
code: KeyCode::Tab, ..
}
| KeyEvent {
code: KeyCode::Char('n'),
modifiers: KeyModifiers::CONTROL,
} => {
self.move_down();
}
KeyEvent {
code: KeyCode::Esc, ..
}
| KeyEvent {
code: KeyCode::Char('c'),
modifiers: KeyModifiers::CONTROL,
} => {
return close_fn;
}
KeyEvent {
code: KeyCode::Enter,
..
} => {
if let Some(option) = self.selection() {
(self.callback_fn)(&mut cx.editor, option, Action::Replace);
}
return close_fn;
}
KeyEvent {
code: KeyCode::Char('h'),
modifiers: KeyModifiers::CONTROL,
} => {
if let Some(option) = self.selection() {
(self.callback_fn)(&mut cx.editor, option, Action::HorizontalSplit);
}
return close_fn;
}
KeyEvent {
code: KeyCode::Char('v'),
modifiers: KeyModifiers::CONTROL,
} => {
if let Some(option) = self.selection() {
(self.callback_fn)(&mut cx.editor, option, Action::VerticalSplit);
}
return close_fn;
}
KeyEvent {
code: KeyCode::Char(' '),
modifiers: KeyModifiers::CONTROL,
} => {
self.save_filter();
}
_ => {

We'd need to extract these out. So it would be completely separate from keymap.rs / commands.rs.

What are you trying to remap? I don't think these keys are reconfigurable in other editors so if this is for just for a few common remaps it's okay to add them as aliases rather than to make the picker customizable.

@VuiMuich
Copy link
Contributor Author

VuiMuich commented Oct 17, 2021

I see, thanks for your estimate!

I was actually wondering, how I could get the picker's functions into scope of command or keymap.

As OP of #615 I'd prefer C-k and C-j for moving up and down in the picker, as it feels more natural to me.

Gonna close this PR then and maybe try my luck with #851 instead.

@VuiMuich VuiMuich closed this Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remap keys in picker mode
2 participants