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

Question? Allow querying all keyboard shortcuts? #160

Closed
kgrossjo opened this issue Jan 8, 2017 · 3 comments
Closed

Question? Allow querying all keyboard shortcuts? #160

kgrossjo opened this issue Jan 8, 2017 · 3 comments
Labels

Comments

@kgrossjo
Copy link

kgrossjo commented Jan 8, 2017

  • Version: 2.4 (55)
  • macOS: 10.12.2 (Sierra)

@kemal and I are binding keys while a modal is visible. I guess that makes them modal keys? The problem is: if I have a global key, say Alt-Enter, and I bind that same combination in a "mode", then I have to make sure to re-enable the global version when the "mode" is "done".

The API doc says that enabling a handler automatically disables the other handlers for the same key/modifier combo, so I guess Phoenix already "knows" which handlers exist. So maybe if this information was exposed, then on entering the "mode" we could query for enabled handlers and then re-enable them when leaving the "mode".

Hope that wording makes sense, not sure if I've explained myself well.

@mafredri
Copy link
Contributor

mafredri commented Jan 8, 2017

I don't think there's a solution to your problem with the current API. I had a similar problem, however, and to work around it I created a function which I use to register all my keys (onKey) and created a function to get the handler for a key combination (getHandler).

You can see the relevant functions here here: https://github.com/mafredri/phoenix-config/blob/master/src/key.ts#L31-L73

And for an example where I use it to re-enable the keys that got disabled: https://github.com/mafredri/phoenix-config/blob/master/src/scan.ts#L73-L81

Maybe not ideal, but I hope it can help you along the way 😄.

@kasper
Copy link
Owner

kasper commented Jan 9, 2017

This is somewhat related to #161. Internally, Phoenix does not keep track of the handlers. It’s all event based and I want to keep it that way.

Yes, this could be exposed through managed handlers in the JavaScript-context, but that would expose the internal state of the handlers and would make it possible for the user to retain the value and this would mess the memory management.

It’s better you implement this by managing handlers yourself for the specific use case.

@kgrossjo
Copy link
Author

kgrossjo commented Jan 9, 2017

Thank you @kasper, now I took a look at the code, and it seems that enabling a key just registers a hotkey with the "exclusive" flag, and that automatically overwrites the previous hotkey.

I apologize. The wording of the documentation (where it says that enabling one handler automatically disables the others) suggested to me that you kept track of all the handlers. Now I see it's not implemented like that.

Yes, I now intend to write a RegisteredKey "class" that mostly does like Key but also keeps track of all handlers.

@kasper kasper added the wontfix label Jan 22, 2017
@kasper kasper closed this as completed Jan 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants