Repository navigation
Shortcut activator - #78522
Shortcut activator#78522
Conversation
|
@gspencergoog I think this PR is ready for review. Can you take a look? |
| /// | ||
| /// The `trigger` should be the non-modifier key that is pressed after all the | ||
| /// modifiers, such as [LogicalKeyboardKey.keyC] as in `Ctrl+C`. It must not be | ||
| /// a modifier key (sided or unsided). |
There was a problem hiding this comment.
I don't think it's a good idea to limit the keys that can be used in a shortcut: people won't implement their own subclass, they'll just assume it can't be done. I think that if we're deprecating LogicalKeySet, we should add that other class (it could be the KeySetActivator that you're already planning) to give people a way to migrate without having to implement a new subclass.
Is the reason that you don't want modifier-only shortcuts to be a goal of SingleActivator because of the non-sidedness of the control, meta, etc. flags?
I can see that it might be confusing to say SingleActivator(LogicalKeyboardKey.shiftLeft, shift: true), since now it's not clear whether you're talking about any shift or just shiftLeft, but you could just assert that the trigger isn't a shift, shiftLeft or shiftRight if the shift flag is true. Other than that, I don't see why the modifier keys should be excluded from being triggers.
| /// | ||
| /// The `trigger` should be the non-modifier key that is pressed after all the | ||
| /// modifiers, such as [LogicalKeyboardKey.keyC] as in `Ctrl+C`. It must not be | ||
| /// a modifier key (sided or unsided). |
There was a problem hiding this comment.
Ahh, OK, I didn't notice that it also enforces the key is not pressed. OK, then I guess it'll just have to be a separate class.
|
Update: I'm waiting for the current roll backlog to resolve before merging this potentially breaking PR. |
|
This pull request is not suitable for automatic merging in its current state.
|
Applies #78522 to existing code, by replacing all occurrences of LogicalKeySet to SingleActivator or ShortcutActivator.

This PR introduced a new class,
ShortcutActivator, and refactored the the definition and lookup system of shortcuts, in order to solve a few issues of the previous algorithm.ShortcutActivatoris designed to be another base class ofLogicalKeySet, and the new standard interface to define a key combination and be mapped to anIntent.LogicalKeySetnow implementsShortcutActivator, keeping its previous behavior. However, when defining typical shortcuts such asDeleteorCtrl-C, it's recommended to use the newSingleActivatorinstead, which behaves more closely to how common OSs do by addressing following issues.This is part of the general keyboard project as in #44918.
Why
LogicalKeySetas a set of keys does not satisfy the need for properly defining shortcut key combinations. Most typical OSs handle shortcuts by treating modifiers and non-modifiers differently.Cwhile holdingCtrl-Aalso triggersCtrl-C.Ctrlwhile holdingCwill not triggerCtrl-C.This shows that modifiers and non-modifiers are born unequal, and it's impossible to properly handle them using a set.
Lookup
Some extent of indexing, instead full linear search, is still desired for performance.
ShortcutActivatortherefore splits requirements into two parts:triggers, a set of logical keys, andaccepts, a predicate function to judge whether the event and keyboard state fully satisty the conditions.Prompt-intent pairs are indexed by
triggers, such as keyCas inCtrl-C, or bothAandBas inAlt-A-B. When a trigger key occurs, all activators are tested linearly to find the first matching intent.Other changes
The algorithm to synchronize modifiers on Web has been change to allow more refined behaviors related to modifiers. More specifically,
metaStatereports their flag as released, the keys of both sides will be set as released. (Previously: unhandled.)metaStatereports their flag as pressed, the left key will be set as pressed. (Previously: both sides pressed.)metaStatereports their flag as pressed too, no synchronization will be added. (Previously: both sides pressed.)Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.