-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add attachCustomKeyEventHandler #712
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
Conversation
| this.handler(key); | ||
|
|
||
| return false; | ||
| return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to return true in order to test customKeypressHandler behavior. I checked source code and this return value seems unused.
|
I never really liked custom keydown handler, I wonder if we could do this a different way. I'm also concerned that we may track the Do you think this would work if |
|
Apply this same handler in I think that all people that using this custom handler, use Another way than custom handler could be an |
|
Let me know how I can modify this PR to suit your needs |
|
I did a quick test and it seems to work for what I have as well so what if we use |
|
@Tyriar Sounds sane. What is the API you have in mind for |
|
@parisk that's what I'm thinking. Since it's the actual event as well consumers are free to check the @chabou so I think we want a single API |
Use a uniq customKeyEventHandler for keyDown and keyPress events Mark and warn attachCustomKeydownHandler() as deprecated.
|
A warning message is now written into console when Do you think that |
Tyriar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
parisk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
|
|
|
@chabou done 😄 |
What
This PR add a
attachCustomKeypressHandlerfunction. It acts exactly likeattachCustomKeydownHandlerbut forkeypressevents.Why
I'm using
attachCustomKeydownHandlerto preventxtermto print some hotkeys. I want to intercept these events so I am returningfalsebut I can't usepreventDefault()on this keydown event because it will break (Electron) hotkey system. In this case, I need to preventxtermto consume next keypress event too. But I can't.How
I decided to duplicate Handlers, one for keydown events and another one for keypress events. The main reason is backward compatibility.
It could be made differently: adding a
attachCustomKeyEventsHandlerused forTerminal.prototype.keyDownandTerminal.prototype.keyPress. In this case, we need to print a warning inattachCustomKeydownHandlerwhen used to mark it deprecated.