Refactor global shortcut initialisation
We initialise keyboard shortcuts in a awkward way, which requires hacks like that noted in ~/behaviors/shortcuts.js#L27-28
.
The current process is something like this:
- A global behaviour initialises the generic
Shortcuts
class only for pages not explicitly, statically listed. - The listed pages instead instantiate (in theory) their own subclass of
Shortcuts
, e.g.projects:activity
.
The problem with this approach is that it's possible for that list of pages to get out of date, such that either no shortcuts get set up, or both the generic Shortcuts
and a subclass get set up. This latter case is the reason for things like !18782 (comment 288243817) (see also !112598 (comment 1287240114)).
A new approach could look like this:
- A single
Shortcuts
instance is always set up for all pages. This instance would be a singleton - either as an exported class instance, or something that relies on ES module state. - Pages that want to change/modify shortcuts would call a
register
method on the shortcuts singleton, which would add/modify shortcuts, and perform any other necessary set up.
This approach means we wouldn't need to maintain a static list of pages, and we'd still get the benefits of tree shaking.
Previous work
- Clean up and refactor global shortcuts (!117666 - merged)
-
Refactor Shortcuts architecture (!117738 - merged)
-
This would address the problems described in this issue, but it feels over-engineered. I'm putting it aside for the moment, but it probably will be at least part of the eventual solution.I reduced its scope, and hopefully can get merged.
-
Edited by Mark Florian