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

Key remapping for compositor components #5505

Open
the-mikedavis opened this issue Jan 11, 2023 · 6 comments
Open

Key remapping for compositor components #5505

the-mikedavis opened this issue Jan 11, 2023 · 6 comments
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements E-hard Call for participation: Experience needed to fix: Hard / a lot

Comments

@the-mikedavis
Copy link
Member

There are some prior issues on this for pickers, prompts, and popups. This issue is meant to be a tracking issue for key remapping for any Component. Ideally you should be able to remap any actions for any component (pickers, prompts, menus, etc.). I think that the solution to remapping for one component should be the same or very similar to the solution for remapping any component so this issue covers all components.

This is a little tricky implementation-wise: regular commands share the same function signature that takes a &mut Context. Component commands are currently built straight into each component. For example see scrolling a popup:

ctrl!('d') => {
self.scroll(self.size.1 as usize / 2, true);
EventResult::Consumed(None)
}
ctrl!('u') => {
self.scroll(self.size.1 as usize / 2, false);
EventResult::Consumed(None)
}

This will also take some design work to decide how the config should look. I am imagining something like:

# ~/.config/helix/config.toml
[keys.normal]
# this section already exists for regular bindings, along with keys.insert and keys.select
[keys.popup]
C-j = "scroll_popup_down"
C-k = "scroll_popup_up"
# maybe these can be namespaced, like `C-j = "popup::scroll_down"`?
[keys.picker]
C-space = "validate_picker_selection"
@goyalyashpal
Copy link
Contributor

hi! would this be applicable to command output popups #5923 (comment) too?

@the-mikedavis
Copy link
Member Author

Yep, the :run-shell-command/:sh command creates a Popup element and Popups are Components

@goyalyashpal
Copy link
Contributor

goyalyashpal commented Feb 19, 2023

hey!

currently

  • the keys seem to be tied to the component - so,
    • C-d works in command output popups,
    • C-n/<tab> works in picker
    • hjkl works in editor (despite having other components open)

so, this concept of being able to "remap" is there in all of the above issues,


but the following thing seems to be not discussed. how about having

  • the ability to change the current active component
  • so that some carefully selected keys (took from editor modes) work across any component as long as it's the active one?

That is, there will be 3 groups of actions for a general component:

  • Normal mode: one grp for navigating between components and fields (so, similar to Tab in web browsers)
  • Normal mode: other for navigating within the field (the hjkl move cursor)
  • Insert mode: last group for entering text (where there's no text field, it may optionally do the "search and jump to")

@tdelabro
Copy link

I wasn't happy with the scroll-in popup keymaps, because while in insert mode, if an autocompletion popup suggestion is open, I cannot use the C-d keymap that I already remaped in [keys.insert], as it is catch by the popup component before the insert one.

So I opened my config file and typed this by instinct:

[keys.popup]
C-u = "no_op"
C-d = "no_op"
C-j = "scroll_down"
C-k = "scroll_up"

and got the following error: Failed to load config: TOML parse error at line 29, column 7 |29 | [keys.popup] | ^^^^^Invalid mode 'popup'.

I'm discovering with this issue that it is not possible yet to remap those keys, but I want to sat that your design suggestion for the config is right imo

@the-mikedavis the-mikedavis added E-hard Call for participation: Experience needed to fix: Hard / a lot and removed E-medium Call for participation: Experience needed to fix: Medium / intermediate labels Jun 25, 2023
@gabydd
Copy link
Member

gabydd commented Jul 30, 2023

have had some more time to experiment with this, what I am currently doing is name spacing the commands by adding the module name to the start of the command so ui::picker::page_down turns into picker_page_down, I was also doing this for the command name but we could instead turn the name into page::down (one line change to the component_commands macro). To make the actual commands work I created AnyPicker and AnyMenu traits(haven't implemented commands for all the components, nor are the commands names totally correct but that should be relatively easy to fix) that have the functions needed for any command on those components. Because you can't downcast from any(the Component to a trait as far as I can tell, I made the component passed to the commands an enum so commands can match for the right component.

currently it allows remapping for the picker, buffer-picker and menu, I can implement the rest of the components if we want as well, branch is here built on the great work of @the-mikedavis : https://github.com/gabydd/helix/tree/md-compositor-key-remapping-idea

change for namespaced version of compositor command naming
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index ecd4ad42..b2e4fdad 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -209,7 +209,7 @@ macro_rules! component_commands {
             paste! {
                 #[allow(non_upper_case_globals)]
                 pub const [<$second _ $name>]: Self = Self::Component {
-                    name: stringify!([<$second _ $name>]),
+                    name: concat!(stringify!($second), "::", stringify!($name)),
                     fun: $first::$second::$name,
                     doc: $doc
                 };

@ykerit
Copy link

ykerit commented May 10, 2024

Really looking forward to the key bindings, when will they happen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements E-hard Call for participation: Experience needed to fix: Hard / a lot
Projects
None yet
Development

No branches or pull requests

5 participants