Upgrade `mousetrap` dependency from 1.4.6
Summary
mousetrap
is a JS library for handling keyboard shortcuts. We use mousetrap
1.4.6, which listens to keyboard events globally. Version >=1.5.0 has an important improvement where you can bind an instance of mousetrap
to a DOM element, which is useful when handling keyboard shortcuts for individual components, e.g. the Markdown editor. In 1.4.6, we instead achieve this by providing a callback to determine whether a keypress should be processed or not. This method is not particularly maintainable.
I propose we upgrade to the latest version of mousetrap
(1.6.3 at this moment) to take advantage of this feature, as well as better compatibility with Node and Vue.
Improvements
- Components making use of keyboard shortcuts will be easier to read and write
- Components making use of keyboard shortcuts will no longer have side-effects
- We get rid of some callback spaghetti
Risks
No big ones. Keyboard shortcuts are used in few places so far, so let's make this better while the scope is narrow.
Involved components
Files importing the mousetrap
library:
app/assets/javascripts/behaviors/shortcuts/shortcuts.js
app/assets/javascripts/behaviors/shortcuts/shortcuts_blob.js
app/assets/javascripts/behaviors/shortcuts/shortcuts_find_file.js
app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js
app/assets/javascripts/behaviors/shortcuts/shortcuts_navigation.js
app/assets/javascripts/behaviors/shortcuts/shortcuts_network.js
app/assets/javascripts/behaviors/shortcuts/shortcuts_wiki.js
app/assets/javascripts/diffs/components/app.vue
app/assets/javascripts/docs/docs_bundle.js
app/assets/javascripts/vue_shared/components/file_finder/index.vue
app/assets/javascripts/zen_mode.js
spec/javascripts/diffs/components/app_spec.js
spec/javascripts/vue_shared/components/file_finder/index_spec.js
spec/javascripts/zen_mode_spec.js
Optional: Missing test coverage
mousetrap@1.6.3
currently breaks some RSpecs for reasons unclear.