Skip to content

Commit 5519f39

Browse files
AlinaVarkkiDevtools-frontend LUCI CQ
authored andcommitted
[RPP] Pass array of bindings to the Shortcuts Dialog instead of one string that needs to be split
We might have multiple shortcuts for one actions that consists of multiple keys. Intead of splitting the keys in ShortcutsDialog component, let's just pass an array of them This allows to add '+' as a key : https://screenshot.googleplex.com/inueasKW4wVVPh7 Bug: 313757601 Change-Id: I797125f564b736508dc377fa90414681ccb83d63 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6039160 Reviewed-by: Nancy Li <[email protected]> Auto-Submit: Alina Varkki <[email protected]> Commit-Queue: Nancy Li <[email protected]> Commit-Queue: Alina Varkki <[email protected]>
1 parent fd8de19 commit 5519f39

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

front_end/panels/recorder/RecorderController.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,10 +1038,11 @@ export class RecorderController extends LitElement {
10381038
}
10391039

10401040
#getShortcutsInfo(): Dialogs.ShortcutDialog.Shortcut[] {
1041-
const getBindingForAction = (action: Actions.RecorderActions): string[] => {
1041+
const getBindingForAction = (action: Actions.RecorderActions): string[][] => {
10421042
const shortcuts = UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction(action);
1043-
1044-
return shortcuts.map(shortcut => shortcut.title());
1043+
const shortcutsWithSplitBindings =
1044+
shortcuts.map(shortcut => shortcut.title().split(/[\s+]+/).map(word => word.trim()));
1045+
return shortcutsWithSplitBindings;
10451046
};
10461047

10471048
return [
@@ -1053,7 +1054,7 @@ export class RecorderController extends LitElement {
10531054
title: i18nString(UIStrings.replayRecording),
10541055
bindings: getBindingForAction(Actions.RecorderActions.REPLAY_RECORDING),
10551056
},
1056-
{title: i18nString(UIStrings.copyShortcut), bindings: [`${Host.Platform.isMac() ? '⌘ C' : 'Ctrl+C'}`]},
1057+
{title: i18nString(UIStrings.copyShortcut), bindings: Host.Platform.isMac() ? [['⌘', 'C']] : [['Ctrl', 'C']]},
10571058
{
10581059
title: i18nString(UIStrings.toggleCode),
10591060
bindings: getBindingForAction(Actions.RecorderActions.TOGGLE_CODE_VIEW),

front_end/panels/timeline/TimelinePanel.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,18 +1143,21 @@ export class TimelinePanel extends UI.Panel.Panel implements Client, TimelineMod
11431143
#getShortcutsInfo(isNavClassic: boolean): ShortcutDialog.ShortcutDialog.Shortcut[] {
11441144
if (isNavClassic) {
11451145
return [
1146-
{title: i18nString(UIStrings.timelineScrollUpDown), bindings: ['Shift Scroll']},
1147-
{title: i18nString(UIStrings.timelineZoomInOut), bindings: ['Scroll', 'W/S']},
1148-
{title: i18nString(UIStrings.timelineFastZoomInOut), bindings: ['Shift W/S']},
1149-
{title: i18nString(UIStrings.timelinePanLeftRight), bindings: ['A/D']},
1146+
{title: i18nString(UIStrings.timelineScrollUpDown), bindings: [['Shift', 'Scroll']]},
1147+
{title: i18nString(UIStrings.timelineZoomInOut), bindings: [['Scroll'], ['W/S']]},
1148+
{title: i18nString(UIStrings.timelineFastZoomInOut), bindings: [['Shift', 'W/S']]},
1149+
{title: i18nString(UIStrings.timelinePanLeftRight), bindings: [['A/D']]},
11501150
];
11511151
}
11521152

11531153
return [
1154-
{title: i18nString(UIStrings.timelineScrollUpDown), bindings: ['Scroll', 'Shift up/down']},
1155-
{title: i18nString(UIStrings.timelineZoomInOut), bindings: ['Cmd Scroll', 'W/S', '+/-']},
1156-
{title: i18nString(UIStrings.timelineFastZoomInOut), bindings: ['Shift W/S', 'Shift +/-']},
1157-
{title: i18nString(UIStrings.timelinePanLeftRight), bindings: ['A/D', 'Shift Scroll', 'Shift left/right']},
1154+
{title: i18nString(UIStrings.timelineScrollUpDown), bindings: [['Scroll'], ['Shift', 'up/down']]},
1155+
{title: i18nString(UIStrings.timelineZoomInOut), bindings: [['Cmd', 'Scroll'], ['W/S'], ['+/-']]},
1156+
{title: i18nString(UIStrings.timelineFastZoomInOut), bindings: [['Shift', 'W/S'], ['Shift', '+/-']]},
1157+
{
1158+
title: i18nString(UIStrings.timelinePanLeftRight),
1159+
bindings: [['A/D'], ['Shift', 'Scroll'], ['Shift', 'left/right']],
1160+
},
11581161
];
11591162
}
11601163

front_end/ui/components/dialogs/ShortcutDialog.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describeWithLocale('ShortcutDialog', () => {
1818
if (prependedElement) {
1919
shortcutDialog.prependElement(prependedElement);
2020
}
21-
shortcutDialog.data = {shortcuts: [{title: 'Shortcut Title', bindings: ['Ctrl+E']}], open};
21+
shortcutDialog.data = {shortcuts: [{title: 'Shortcut Title', bindings: [['Ctrl+E']]}], open};
2222
Helpers.renderElementIntoDOM(shortcutDialog);
2323
await coordinator.done();
2424

front_end/ui/components/dialogs/ShortcutDialog.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ declare global {
3737

3838
export interface Shortcut {
3939
title: string|Platform.UIString.LocalizedString;
40-
bindings: string[];
40+
bindings: string[][];
4141
}
4242
export interface ShortcutDialogData {
4343
shortcuts: Shortcut[];
@@ -65,10 +65,6 @@ export class ShortcutDialog extends HTMLElement {
6565
void ComponentHelpers.ScheduledRender.scheduleRender(this, this.#renderBound);
6666
}
6767

68-
#getKeysFromBinding(binding: string): string[] {
69-
return binding.split(/[\s+]+/).map(word => word.trim()); // Split on one or more spaces or + symbols
70-
}
71-
7268
prependElement(element: HTMLElement): void {
7369
this.#prependedElement = element;
7470
}
@@ -99,7 +95,7 @@ export class ShortcutDialog extends HTMLElement {
9995
${shortcut.bindings.map(binding => {
10096
return html`
10197
<div class="keys-container">
102-
${this.#getKeysFromBinding(binding).map(key => html`
98+
${binding.map(key => html`
10399
<span class="keybinds-key">${key}</span>
104100
`)}
105101
</div>

front_end/ui/components/docs/dialog/shortcut_dialog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ shortcutDialog.data = {
1414
shortcuts: [
1515
{
1616
title: 'First Shortcut Title',
17-
bindings: ['Ctrl+E'],
17+
bindings: [['Ctrl+E']],
1818
},
1919
{
2020
title: 'Second Shortcut Title',
21-
bindings: ['Ctrl+Enter', 'F8'],
21+
bindings: [['Ctrl', 'Enter'], ['F8']],
2222
},
2323
],
2424
};

0 commit comments

Comments
 (0)