Multiple keymaps and mousetrap#2412
Merged
Merged
Conversation
Contributor
Author
albinekb
reviewed
Oct 30, 2017
|
|
||
| const commands = { | ||
| 'window:new': () => { | ||
| // If window is created on the same tick, it will consume event too |
Stanzilla
reviewed
Oct 30, 2017
| { | ||
| "compilerOptions": { | ||
| "checkJs": true, | ||
| "checkJs": false, |
Contributor
There was a problem hiding this comment.
that probably slipped in by mistake?
Contributor
Author
There was a problem hiding this comment.
I turned it off because there is a lot of warning that are not relevant but yes: it shouldn't be in this PR.
Member
|
This PR looks fantastic to me. Let's get it into canary! |
Contributor
|
Great work @chabou |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a HUGE PR.
I tried to clean my git history but this is really hard to rebase with some merge commits 😞
This PR have 2 goals:
mousetrapto intercept and interpret key events because it is smarter than ElectronI will not explain how worked keymaps but I need to rewrite it a lot. This how it works now:
Keymap configuration
Configuration is now stored in a unique place. A normalized
keymapsobject directly in mainconfigobject:User can define a command with a single shortcut or an array of shortcuts.
Plugin can add some command/keymaps using a new function:
decorateKeymapsthat is applied like other decorating functions: keymap is passed to this plugin handler and plugin can add a shortcut to a command or completely overwrite/remove a shortcut. PreviousextendKeymapsfunction has been marked as deprecated.Normalization consists of these steps :
cmdis warned and transformed tocommandto suitmousetraprequirements.*:prefixcommands are extrapolated to*:1,*:2...*:lastcommands.Mousetrap interception
When
hypercontainer is mounted,mousetrapis instanciated and all keybindings are made. For now, my fork is declared as dependency. I made a PR to include an option to makemousetrapto intercept keys on capturing phase and not only on bubbling phase. Why? Without this feature,xtermwould receive keys beforemousetrapand we would need to duplicate key analysis to know ifxtermshould ignore this event or not. With this feature, everymousetrapbinding flags key events andxtermkeyboard handler can rely on this flag to ignore events or not.Command triggering
When a configured shortcut is hit, binded
mousetrapfunction is called. This function verifies if there is an handler registered by a plugin for this command. If there is one, it call this handler with key event in parameter. If not, this function dispatch a redux action that make a RPC call as a side effect. This redux action can be logged, changed or discarded by plugins like any redux action. RPC call iscommandwith command as parameter (like'pane:splitVertical'). This RPC is binded to commands that can trigger an RPC call to focusedWindow. Some action like copy/paste are handled directly by Electron with its menu-item role mechanism. In order to trigger them, we need to intercept them bymousetraplike other actions, but we can't preventDefault in order to let Electron act. That's why we have a whitelist of actions that should not be prevented.We need to prevent default for other events because commands are registered with
mousetrapbinding to have multiple shortcuts and Electron's menuItems to be clicked. If defaults were not prevented, commands would be triggered twice.Some actions could be trigger directly by
mousetrapbinded function because this is renderer-only actions (like pane splitting) but I prefer to stick to actual behaviour: command are always triggered by mainProcess even if its source is a shotrcut hit in BrowserWindow.What is missing?