Centralize shortcut titles
There are a few parts of the UI that assume that shortcuts will only be
one key (e.g. the shortcut tooltips displayed for some buttons), so this
CL updates them to access a new KeyboardShortcut.title() method to get
the name of a shortcut rather than just getting the name of a single
keypress from its Descriptor. The current/legacy Shortcuts settings tab
was one of these places, but I left it alone because it will be
obsoleted by the new custom shortcuts tab in the future and in the
meantime the only users who will have any chords enabled in the DevTools
will be those who have opted in to the custom shortcuts experiment and
enabled VS Code shortcuts.
Custom shortcuts doc: https://docs.google.com/document/d/1oOPSWPxCHvMoBZ0Fw9jwFZt6gP4lrsrsl8DEAp-Hy7o/edit#
Bug: 174309
Change-Id: Ic56fb14129a417ed441fc46401af226db52c8905
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2158086
Commit-Queue: Jack Lynch <[email protected]>
Reviewed-by: Robert Paveza <[email protected]>
diff --git a/front_end/ui/ShortcutRegistry.js b/front_end/ui/ShortcutRegistry.js
index 7a25cc4..6f7ffa0 100644
--- a/front_end/ui/ShortcutRegistry.js
+++ b/front_end/ui/ShortcutRegistry.js
@@ -68,11 +68,15 @@
}
/**
+ * @deprecated this function is obsolete and will be removed in the
+ * future along with the legacy shortcuts settings tab
+ * crbug.com/174309
+ *
* @param {string} actionId
* @return {!Array.<!Descriptor>}
*/
shortcutDescriptorsForAction(actionId) {
- return [...this._actionToShortcut.get(actionId)].map(shortcut => shortcut.descriptor);
+ return [...this._actionToShortcut.get(actionId)].map(shortcut => shortcut.descriptors[0]);
}
/**
@@ -80,14 +84,10 @@
* @return {!Array.<number>}
*/
keysForActions(actionIds) {
- const result = [];
- for (let i = 0; i < actionIds.length; ++i) {
- const descriptors = this.shortcutDescriptorsForAction(actionIds[i]);
- for (let j = 0; j < descriptors.length; ++j) {
- result.push(descriptors[j].key);
- }
- }
- return result;
+ const keys = actionIds.flatMap(
+ action => [...this._actionToShortcut.get(action)].flatMap(
+ shortcut => shortcut.descriptors.map(descriptor => descriptor.key)));
+ return [...(new Set(keys))];
}
/**
@@ -95,9 +95,9 @@
* @return {string|undefined}
*/
shortcutTitleForAction(actionId) {
- const descriptors = this.shortcutDescriptorsForAction(actionId);
- if (descriptors.length) {
- return descriptors[0].name;
+ const shortcuts = this._actionToShortcut.get(actionId);
+ if (shortcuts.size) {
+ return shortcuts.firstValue().title();
}
}
@@ -116,7 +116,7 @@
eventMatchesAction(event, actionId) {
console.assert(this._actionToShortcut.has(actionId), 'Unknown action ' + actionId);
const key = KeyboardShortcut.makeKeyFromEvent(event);
- return [...this._actionToShortcut.get(actionId)].some(shortcut => shortcut.descriptor.key === key);
+ return [...this._actionToShortcut.get(actionId)].some(shortcut => shortcut.descriptors[0].key === key);
}
/**
@@ -219,7 +219,7 @@
*/
_registerShortcut(shortcut) {
this._actionToShortcut.set(shortcut.action, shortcut);
- this._keyToShortcut.set(shortcut.descriptor.key, shortcut);
+ this._keyToShortcut.set(shortcut.descriptors[0].key, shortcut);
}
_registerBindings() {
@@ -240,7 +240,7 @@
const shortcutDescriptor = KeyboardShortcut.makeDescriptorFromBindingShortcut(bindings[i].shortcut);
if (shortcutDescriptor) {
this._registerShortcut(new KeyboardShortcut(
- shortcutDescriptor, /** @type {string} */ (descriptor.actionId), Type.DefaultShortcut));
+ [shortcutDescriptor], /** @type {string} */ (descriptor.actionId), Type.DefaultShortcut));
}
}
}