blob: 1da280c42dd488b7ce33424f824ff8bbdad7bc88 [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
Paul Lewis17e384e2020-01-08 15:46:5131import * as Common from '../common/common.js';
Paul Lewis0fd43712020-01-08 17:07:3632import * as Host from '../host/host.js';
33
Paul Lewis9950e182019-12-16 16:06:0734import {KeyboardShortcut, Keys, Modifiers} from './KeyboardShortcut.js';
35import {createDocumentationLink} from './UIUtils.js';
36import {Widget} from './Widget.js';
37
Blink Reformat4c46d092018-04-07 15:32:3738/**
39 * @unrestricted
40 */
Paul Lewis9950e182019-12-16 16:06:0741export class ShortcutsScreen {
Blink Reformat4c46d092018-04-07 15:32:3742 constructor() {
Tim van der Lippe0830b3d2019-10-03 13:20:0743 /** @type {!Object.<string, !ShortcutsSection>} */
Blink Reformat4c46d092018-04-07 15:32:3744 this._sections = {};
45 }
46
47 static registerShortcuts() {
48 // Elements panel
Paul Lewis17e384e2020-01-08 15:46:5149 const elementsSection = UI.shortcutsScreen.section(Common.UIString.UIString('Elements Panel'));
Blink Reformat4c46d092018-04-07 15:32:3750
Tim van der Lippe0830b3d2019-10-03 13:20:0751 const navigate = ElementsPanelShortcuts.NavigateUp.concat(ElementsPanelShortcuts.NavigateDown);
Paul Lewis17e384e2020-01-08 15:46:5152 elementsSection.addRelatedKeys(navigate, Common.UIString.UIString('Navigate elements'));
Blink Reformat4c46d092018-04-07 15:32:3753
Tim van der Lippe0830b3d2019-10-03 13:20:0754 const expandCollapse = ElementsPanelShortcuts.Expand.concat(ElementsPanelShortcuts.Collapse);
Paul Lewis17e384e2020-01-08 15:46:5155 elementsSection.addRelatedKeys(expandCollapse, Common.UIString.UIString('Expand/collapse'));
Blink Reformat4c46d092018-04-07 15:32:3756
Paul Lewis17e384e2020-01-08 15:46:5157 elementsSection.addAlternateKeys(ElementsPanelShortcuts.EditAttribute, Common.UIString.UIString('Edit attribute'));
Blink Reformat4c46d092018-04-07 15:32:3758 elementsSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:5159 UI.shortcutRegistry.shortcutDescriptorsForAction('elements.hide-element'),
60 Common.UIString.UIString('Hide element'));
Blink Reformat4c46d092018-04-07 15:32:3761 elementsSection.addAlternateKeys(
Joel Einbindera66e5bf2018-05-31 01:26:3762 UI.shortcutRegistry.shortcutDescriptorsForAction('elements.edit-as-html'),
Paul Lewis17e384e2020-01-08 15:46:5163 Common.UIString.UIString('Toggle edit as HTML'));
Blink Reformat4c46d092018-04-07 15:32:3764
Fabio Rochaf0d95472019-05-28 21:35:1965 // Styles pane
Paul Lewis17e384e2020-01-08 15:46:5166 const stylesPaneSection = UI.shortcutsScreen.section(Common.UIString.UIString('Styles Pane'));
Blink Reformat4c46d092018-04-07 15:32:3767
Tim van der Lippe0830b3d2019-10-03 13:20:0768 const nextPreviousProperty = ElementsPanelShortcuts.NextProperty.concat(ElementsPanelShortcuts.PreviousProperty);
Paul Lewis17e384e2020-01-08 15:46:5169 stylesPaneSection.addRelatedKeys(nextPreviousProperty, Common.UIString.UIString('Next/previous property'));
Blink Reformat4c46d092018-04-07 15:32:3770
Paul Lewis17e384e2020-01-08 15:46:5171 stylesPaneSection.addRelatedKeys(
72 ElementsPanelShortcuts.IncrementValue, Common.UIString.UIString('Increment value'));
73 stylesPaneSection.addRelatedKeys(
74 ElementsPanelShortcuts.DecrementValue, Common.UIString.UIString('Decrement value'));
Blink Reformat4c46d092018-04-07 15:32:3775
Paul Lewis17e384e2020-01-08 15:46:5176 stylesPaneSection.addAlternateKeys(
77 ElementsPanelShortcuts.IncrementBy10, Common.UIString.UIString('Increment by %f', 10));
78 stylesPaneSection.addAlternateKeys(
79 ElementsPanelShortcuts.DecrementBy10, Common.UIString.UIString('Decrement by %f', 10));
Blink Reformat4c46d092018-04-07 15:32:3780
Paul Lewis17e384e2020-01-08 15:46:5181 stylesPaneSection.addAlternateKeys(
82 ElementsPanelShortcuts.IncrementBy100, Common.UIString.UIString('Increment by %f', 100));
83 stylesPaneSection.addAlternateKeys(
84 ElementsPanelShortcuts.DecrementBy100, Common.UIString.UIString('Decrement by %f', 100));
Blink Reformat4c46d092018-04-07 15:32:3785
Paul Lewis17e384e2020-01-08 15:46:5186 stylesPaneSection.addAlternateKeys(
87 ElementsPanelShortcuts.IncrementBy01, Common.UIString.UIString('Increment by %f', 0.1));
88 stylesPaneSection.addAlternateKeys(
89 ElementsPanelShortcuts.DecrementBy01, Common.UIString.UIString('Decrement by %f', 0.1));
Blink Reformat4c46d092018-04-07 15:32:3790
Fabio Rochaf0d95472019-05-28 21:35:1991 // Console
Paul Lewis17e384e2020-01-08 15:46:5192 const consoleSection = UI.shortcutsScreen.section(Common.UIString.UIString('Console'));
Blink Reformat4c46d092018-04-07 15:32:3793
Fabio Rochaf0d95472019-05-28 21:35:1994 consoleSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:5195 UI.shortcutRegistry.shortcutDescriptorsForAction('console.clear'), Common.UIString.UIString('Clear console'));
96 consoleSection.addRelatedKeys(
97 ConsolePanelShortcuts.AcceptSuggestion, Common.UIString.UIString('Accept suggestion'));
98 consoleSection.addAlternateKeys(
99 ConsolePanelShortcuts.ClearConsolePrompt, Common.UIString.UIString('Clear console prompt'));
100 consoleSection.addRelatedKeys(
101 ConsolePanelShortcuts.NextPreviousLine, Common.UIString.UIString('Next/previous line'));
Fabio Rochaf0d95472019-05-28 21:35:19102
Paul Lewis0fd43712020-01-08 17:07:36103 if (Host.Platform.isMac()) {
Fabio Rochaf0d95472019-05-28 21:35:19104 consoleSection.addRelatedKeys(
Paul Lewis17e384e2020-01-08 15:46:51105 ConsolePanelShortcuts.NextPreviousCommand, Common.UIString.UIString('Next/previous command'));
Fabio Rochaf0d95472019-05-28 21:35:19106 }
107
Paul Lewis17e384e2020-01-08 15:46:51108 consoleSection.addKey(ConsolePanelShortcuts.ExecuteCommand, Common.UIString.UIString('Execute command'));
Fabio Rochaf0d95472019-05-28 21:35:19109
110 // Debugger
Paul Lewis17e384e2020-01-08 15:46:51111 const debuggerSection = UI.shortcutsScreen.section(Common.UIString.UIString('Debugger'));
Fabio Rochaf0d95472019-05-28 21:35:19112
113 debuggerSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51114 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-pause'),
115 Common.UIString.UIString('Pause/ Continue'));
Fabio Rochaf0d95472019-05-28 21:35:19116 debuggerSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51117 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.step-over'), Common.UIString.UIString('Step over'));
Fabio Rochaf0d95472019-05-28 21:35:19118 debuggerSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51119 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.step-into'), Common.UIString.UIString('Step into'));
Fabio Rochaf0d95472019-05-28 21:35:19120 debuggerSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51121 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.step-out'), Common.UIString.UIString('Step out'));
Blink Reformat4c46d092018-04-07 15:32:37122
123 const nextAndPrevFrameKeys =
124 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.next-call-frame')
125 .concat(UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.previous-call-frame'));
Paul Lewis17e384e2020-01-08 15:46:51126 debuggerSection.addRelatedKeys(nextAndPrevFrameKeys, Common.UIString.UIString('Next/previous call frame'));
Blink Reformat4c46d092018-04-07 15:32:37127
Fabio Rochaf0d95472019-05-28 21:35:19128 debuggerSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51129 SourcesPanelShortcuts.EvaluateSelectionInConsole, Common.UIString.UIString('Evaluate selection in console'));
Fabio Rochaf0d95472019-05-28 21:35:19130 debuggerSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51131 SourcesPanelShortcuts.AddSelectionToWatch, Common.UIString.UIString('Add selection to watch'));
Fabio Rochaf0d95472019-05-28 21:35:19132 debuggerSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37133 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-breakpoint'),
Paul Lewis17e384e2020-01-08 15:46:51134 Common.UIString.UIString('Toggle breakpoint'));
Fabio Rochaf0d95472019-05-28 21:35:19135 debuggerSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37136 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-breakpoint-enabled'),
Paul Lewis17e384e2020-01-08 15:46:51137 Common.UIString.UIString('Toggle breakpoint enabled'));
Fabio Rochaf0d95472019-05-28 21:35:19138 debuggerSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37139 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-breakpoints-active'),
Paul Lewis17e384e2020-01-08 15:46:51140 Common.UIString.UIString('Toggle all breakpoints'));
Olivia Flynn8e746e02019-06-19 17:06:23141 debuggerSection.addAlternateKeys(
142 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.breakpoint-input-window'),
143 ls`Open breakpoint editor`);
Blink Reformat4c46d092018-04-07 15:32:37144
145 // Editing
Paul Lewis17e384e2020-01-08 15:46:51146 const editingSection = UI.shortcutsScreen.section(Common.UIString.UIString('Text Editor'));
Fabio Rochaf0d95472019-05-28 21:35:19147
148 editingSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51149 UI.shortcutRegistry.shortcutDescriptorsForAction('sources.go-to-member'),
150 Common.UIString.UIString('Go to member'));
Fabio Rochaf0d95472019-05-28 21:35:19151 editingSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51152 SourcesPanelShortcuts.ToggleAutocompletion, Common.UIString.UIString('Autocompletion'));
153 editingSection.addAlternateKeys(
154 UI.shortcutRegistry.shortcutDescriptorsForAction('sources.go-to-line'), Common.UIString.UIString('Go to line'));
Fabio Rochaf0d95472019-05-28 21:35:19155 editingSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37156 UI.shortcutRegistry.shortcutDescriptorsForAction('sources.jump-to-previous-location'),
Paul Lewis17e384e2020-01-08 15:46:51157 Common.UIString.UIString('Jump to previous editing location'));
Fabio Rochaf0d95472019-05-28 21:35:19158 editingSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37159 UI.shortcutRegistry.shortcutDescriptorsForAction('sources.jump-to-next-location'),
Paul Lewis17e384e2020-01-08 15:46:51160 Common.UIString.UIString('Jump to next editing location'));
161 editingSection.addAlternateKeys(SourcesPanelShortcuts.ToggleComment, Common.UIString.UIString('Toggle comment'));
Fabio Rochaf0d95472019-05-28 21:35:19162 editingSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51163 SourcesPanelShortcuts.IncreaseCSSUnitByOne, Common.UIString.UIString('Increment CSS unit by 1'));
Fabio Rochaf0d95472019-05-28 21:35:19164 editingSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51165 SourcesPanelShortcuts.DecreaseCSSUnitByOne, Common.UIString.UIString('Decrement CSS unit by 1'));
Fabio Rochaf0d95472019-05-28 21:35:19166 editingSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51167 SourcesPanelShortcuts.IncreaseCSSUnitByTen, Common.UIString.UIString('Increment CSS unit by 10'));
Fabio Rochaf0d95472019-05-28 21:35:19168 editingSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51169 SourcesPanelShortcuts.DecreaseCSSUnitByTen, Common.UIString.UIString('Decrement CSS unit by 10'));
Fabio Rochaf0d95472019-05-28 21:35:19170 editingSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51171 SourcesPanelShortcuts.SelectNextOccurrence, Common.UIString.UIString('Select next occurrence'));
172 editingSection.addAlternateKeys(SourcesPanelShortcuts.SoftUndo, Common.UIString.UIString('Soft undo'));
Fabio Rochaf0d95472019-05-28 21:35:19173 editingSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51174 SourcesPanelShortcuts.GotoMatchingBracket, Common.UIString.UIString('Go to matching bracket'));
Fabio Rochaf0d95472019-05-28 21:35:19175 editingSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37176 UI.shortcutRegistry.shortcutDescriptorsForAction('sources.close-editor-tab'),
Paul Lewis17e384e2020-01-08 15:46:51177 Common.UIString.UIString('Close editor tab'));
Fabio Rochaf0d95472019-05-28 21:35:19178 editingSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37179 UI.shortcutRegistry.shortcutDescriptorsForAction('sources.switch-file'),
Paul Lewis17e384e2020-01-08 15:46:51180 Common.UIString.UIString('Switch between files with the same name and different extensions.'));
Blink Reformat4c46d092018-04-07 15:32:37181
182 // Performance panel
Paul Lewis17e384e2020-01-08 15:46:51183 const performanceSection = UI.shortcutsScreen.section(Common.UIString.UIString('Performance Panel'));
Fabio Rochaf0d95472019-05-28 21:35:19184
185 performanceSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37186 UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.toggle-recording'),
Paul Lewis17e384e2020-01-08 15:46:51187 Common.UIString.UIString('Start/stop recording'));
Fabio Rochaf0d95472019-05-28 21:35:19188 performanceSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37189 UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.record-reload'),
Paul Lewis17e384e2020-01-08 15:46:51190 Common.UIString.UIString('Record page reload'));
Fabio Rochaf0d95472019-05-28 21:35:19191 performanceSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51192 UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.save-to-file'),
193 Common.UIString.UIString('Save profile'));
Fabio Rochaf0d95472019-05-28 21:35:19194 performanceSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51195 UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.load-from-file'),
196 Common.UIString.UIString('Load profile'));
Fabio Rochaf0d95472019-05-28 21:35:19197 performanceSection.addRelatedKeys(
Blink Reformat4c46d092018-04-07 15:32:37198 UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.jump-to-previous-frame')
199 .concat(UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.jump-to-next-frame')),
Paul Lewis17e384e2020-01-08 15:46:51200 Common.UIString.UIString('Jump to previous/next frame'));
Fabio Rochaf0d95472019-05-28 21:35:19201 performanceSection.addRelatedKeys(
Blink Reformat4c46d092018-04-07 15:32:37202 UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.show-history'),
Paul Lewis17e384e2020-01-08 15:46:51203 Common.UIString.UIString('Pick a recording from history'));
Fabio Rochaf0d95472019-05-28 21:35:19204 performanceSection.addRelatedKeys(
Blink Reformat4c46d092018-04-07 15:32:37205 UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.previous-recording')
206 .concat(UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.next-recording')),
Paul Lewis17e384e2020-01-08 15:46:51207 Common.UIString.UIString('Show previous/next recording'));
Blink Reformat4c46d092018-04-07 15:32:37208
209 // Memory panel
Paul Lewis17e384e2020-01-08 15:46:51210 const memorySection = UI.shortcutsScreen.section(Common.UIString.UIString('Memory Panel'));
Fabio Rochaf0d95472019-05-28 21:35:19211
212 memorySection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37213 UI.shortcutRegistry.shortcutDescriptorsForAction('profiler.heap-toggle-recording'),
Paul Lewis17e384e2020-01-08 15:46:51214 Common.UIString.UIString('Start/stop recording'));
Blink Reformat4c46d092018-04-07 15:32:37215
216 // Layers panel
Paul Lewis17e384e2020-01-08 15:46:51217 const layersSection = UI.shortcutsScreen.section(Common.UIString.UIString('Layers Panel'));
Fabio Rochaf0d95472019-05-28 21:35:19218
Paul Lewis17e384e2020-01-08 15:46:51219 layersSection.addAlternateKeys(LayersPanelShortcuts.ResetView, Common.UIString.UIString('Reset view'));
220 layersSection.addAlternateKeys(LayersPanelShortcuts.PanMode, Common.UIString.UIString('Switch to pan mode'));
221 layersSection.addAlternateKeys(LayersPanelShortcuts.RotateMode, Common.UIString.UIString('Switch to rotate mode'));
Fabio Rochaf0d95472019-05-28 21:35:19222 layersSection.addAlternateKeys(
Paul Lewis17e384e2020-01-08 15:46:51223 LayersPanelShortcuts.TogglePanRotate,
224 Common.UIString.UIString('Temporarily toggle pan/rotate mode while held'));
225 layersSection.addAlternateKeys(LayersPanelShortcuts.ZoomIn, Common.UIString.UIString('Zoom in'));
226 layersSection.addAlternateKeys(LayersPanelShortcuts.ZoomOut, Common.UIString.UIString('Zoom out'));
Fabio Rochaf0d95472019-05-28 21:35:19227 layersSection.addRelatedKeys(
Paul Lewis17e384e2020-01-08 15:46:51228 LayersPanelShortcuts.Up.concat(LayersPanelShortcuts.Down), Common.UIString.UIString('Pan or rotate up/down'));
Fabio Rochaf0d95472019-05-28 21:35:19229 layersSection.addRelatedKeys(
Paul Lewis17e384e2020-01-08 15:46:51230 LayersPanelShortcuts.Left.concat(LayersPanelShortcuts.Right),
231 Common.UIString.UIString('Pan or rotate left/right'));
Blink Reformat4c46d092018-04-07 15:32:37232 }
233
234 /**
235 * @param {string} name
Tim van der Lippe0830b3d2019-10-03 13:20:07236 * @return {!ShortcutsSection}
Blink Reformat4c46d092018-04-07 15:32:37237 */
238 section(name) {
239 let section = this._sections[name];
Tim van der Lippe1d6e57a2019-09-30 11:55:34240 if (!section) {
Tim van der Lippe0830b3d2019-10-03 13:20:07241 this._sections[name] = section = new ShortcutsSection(name);
Tim van der Lippe1d6e57a2019-09-30 11:55:34242 }
Blink Reformat4c46d092018-04-07 15:32:37243 return section;
244 }
245
246 /**
Paul Lewis9950e182019-12-16 16:06:07247 * @return {!Widget}
Blink Reformat4c46d092018-04-07 15:32:37248 */
249 createShortcutsTabView() {
250 const orderedSections = [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34251 for (const section in this._sections) {
Blink Reformat4c46d092018-04-07 15:32:37252 orderedSections.push(this._sections[section]);
Tim van der Lippe1d6e57a2019-09-30 11:55:34253 }
Blink Reformat4c46d092018-04-07 15:32:37254 function compareSections(a, b) {
255 return a.order - b.order;
256 }
257 orderedSections.sort(compareSections);
258
Paul Lewis9950e182019-12-16 16:06:07259 const widget = new Widget();
Blink Reformat4c46d092018-04-07 15:32:37260
261 widget.element.className = 'settings-tab-container'; // Override
Chandani Shrestha83bd7c92019-06-11 21:21:59262 widget.element.createChild('header').createChild('h1').createTextChild(ls`Shortcuts`);
Blink Reformat4c46d092018-04-07 15:32:37263 const scrollPane = widget.element.createChild('div', 'settings-container-wrapper');
264 const container = scrollPane.createChild('div');
265 container.className = 'settings-content settings-container';
Tim van der Lippe1d6e57a2019-09-30 11:55:34266 for (let i = 0; i < orderedSections.length; ++i) {
Blink Reformat4c46d092018-04-07 15:32:37267 orderedSections[i].renderSection(container);
Tim van der Lippe1d6e57a2019-09-30 11:55:34268 }
Blink Reformat4c46d092018-04-07 15:32:37269
270 const note = scrollPane.createChild('p', 'settings-footnote');
Paul Lewis9950e182019-12-16 16:06:07271 note.appendChild(createDocumentationLink(
Paul Lewis17e384e2020-01-08 15:46:51272 'iterate/inspect-styles/shortcuts',
273 Common.UIString.UIString('Full list of DevTools keyboard shortcuts and gestures')));
Blink Reformat4c46d092018-04-07 15:32:37274
275 return widget;
276 }
Tim van der Lippe0830b3d2019-10-03 13:20:07277}
Blink Reformat4c46d092018-04-07 15:32:37278
279/**
Blink Reformat4c46d092018-04-07 15:32:37280 * @unrestricted
281 */
Tim van der Lippec96ccd92019-11-29 16:23:54282class ShortcutsSection {
Blink Reformat4c46d092018-04-07 15:32:37283 /**
284 * @param {string} name
285 */
286 constructor(name) {
287 this.name = name;
288 this._lines = /** @type {!Array.<!{key: !Node, text: string}>} */ ([]);
Tim van der Lippe0830b3d2019-10-03 13:20:07289 this.order = ++ShortcutsSection._sequenceNumber;
Blink Reformat4c46d092018-04-07 15:32:37290 }
291
292 /**
293 * @param {!UI.KeyboardShortcut.Descriptor} key
294 * @param {string} description
295 */
296 addKey(key, description) {
297 this._addLine(this._renderKey(key), description);
298 }
299
300 /**
301 * @param {!Array.<!UI.KeyboardShortcut.Descriptor>} keys
302 * @param {string} description
303 */
304 addRelatedKeys(keys, description) {
305 this._addLine(this._renderSequence(keys, '/'), description);
306 }
307
308 /**
309 * @param {!Array.<!UI.KeyboardShortcut.Descriptor>} keys
310 * @param {string} description
311 */
312 addAlternateKeys(keys, description) {
Paul Lewis17e384e2020-01-08 15:46:51313 this._addLine(this._renderSequence(keys, Common.UIString.UIString('or')), description);
Blink Reformat4c46d092018-04-07 15:32:37314 }
315
316 /**
317 * @param {!Node} keyElement
318 * @param {string} description
319 */
320 _addLine(keyElement, description) {
321 this._lines.push({key: keyElement, text: description});
322 }
323
324 /**
325 * @param {!Element} container
326 */
327 renderSection(container) {
328 const parent = container.createChild('div', 'settings-block');
329
330 const headLine = parent.createChild('div', 'settings-line');
331 headLine.createChild('div', 'settings-key-cell');
332 headLine.createChild('div', 'settings-section-title settings-cell').textContent = this.name;
Amanda Baker11630de2019-07-12 02:54:33333 UI.ARIAUtils.markAsHeading(headLine, /* level */ 2);
Blink Reformat4c46d092018-04-07 15:32:37334
335 for (let i = 0; i < this._lines.length; ++i) {
336 const line = parent.createChild('div', 'settings-line');
337 const keyCell = line.createChild('div', 'settings-key-cell');
338 keyCell.appendChild(this._lines[i].key);
339 keyCell.appendChild(this._createSpan('settings-key-delimiter', ':'));
340 line.createChild('div', 'settings-cell').textContent = this._lines[i].text;
341 }
342 }
343
344 /**
345 * @param {!Array.<!UI.KeyboardShortcut.Descriptor>} sequence
346 * @param {string} delimiter
347 * @return {!Node}
348 */
349 _renderSequence(sequence, delimiter) {
350 const delimiterSpan = this._createSpan('settings-key-delimiter', delimiter);
351 return this._joinNodes(sequence.map(this._renderKey.bind(this)), delimiterSpan);
352 }
353
354 /**
355 * @param {!UI.KeyboardShortcut.Descriptor} key
356 * @return {!Node}
357 */
358 _renderKey(key) {
359 const keyName = key.name;
360 const plus = this._createSpan('settings-combine-keys', '+');
361 return this._joinNodes(keyName.split(' + ').map(this._createSpan.bind(this, 'settings-key')), plus);
362 }
363
364 /**
365 * @param {string} className
366 * @param {string} textContent
367 * @return {!Element}
368 */
369 _createSpan(className, textContent) {
370 const node = createElement('span');
371 node.className = className;
372 node.textContent = textContent;
373 return node;
374 }
375
376 /**
377 * @param {!Array.<!Element>} nodes
378 * @param {!Element} delimiter
379 * @return {!Node}
380 */
381 _joinNodes(nodes, delimiter) {
382 const result = createDocumentFragment();
383 for (let i = 0; i < nodes.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34384 if (i > 0) {
Blink Reformat4c46d092018-04-07 15:32:37385 result.appendChild(delimiter.cloneNode(true));
Tim van der Lippe1d6e57a2019-09-30 11:55:34386 }
Blink Reformat4c46d092018-04-07 15:32:37387 result.appendChild(nodes[i]);
388 }
389 return result;
390 }
Tim van der Lippe0830b3d2019-10-03 13:20:07391}
Blink Reformat4c46d092018-04-07 15:32:37392
Tim van der Lippe0830b3d2019-10-03 13:20:07393ShortcutsSection._sequenceNumber = 0;
Blink Reformat4c46d092018-04-07 15:32:37394
395
Tim van der Lippec96ccd92019-11-29 16:23:54396const ElementsPanelShortcuts = {
Paul Lewis9950e182019-12-16 16:06:07397 NavigateUp: [KeyboardShortcut.makeDescriptor(Keys.Up)],
Blink Reformat4c46d092018-04-07 15:32:37398
Paul Lewis9950e182019-12-16 16:06:07399 NavigateDown: [KeyboardShortcut.makeDescriptor(Keys.Down)],
Blink Reformat4c46d092018-04-07 15:32:37400
Paul Lewis9950e182019-12-16 16:06:07401 Expand: [KeyboardShortcut.makeDescriptor(Keys.Right)],
Blink Reformat4c46d092018-04-07 15:32:37402
Paul Lewis9950e182019-12-16 16:06:07403 Collapse: [KeyboardShortcut.makeDescriptor(Keys.Left)],
Blink Reformat4c46d092018-04-07 15:32:37404
Paul Lewis9950e182019-12-16 16:06:07405 EditAttribute: [KeyboardShortcut.makeDescriptor(Keys.Enter)],
Blink Reformat4c46d092018-04-07 15:32:37406
Paul Lewis9950e182019-12-16 16:06:07407 NextProperty: [KeyboardShortcut.makeDescriptor(Keys.Tab)],
Blink Reformat4c46d092018-04-07 15:32:37408
Paul Lewis9950e182019-12-16 16:06:07409 PreviousProperty: [KeyboardShortcut.makeDescriptor(Keys.Tab, Modifiers.Shift)],
Blink Reformat4c46d092018-04-07 15:32:37410
Paul Lewis9950e182019-12-16 16:06:07411 IncrementValue: [KeyboardShortcut.makeDescriptor(Keys.Up)],
Blink Reformat4c46d092018-04-07 15:32:37412
Paul Lewis9950e182019-12-16 16:06:07413 DecrementValue: [KeyboardShortcut.makeDescriptor(Keys.Down)],
Blink Reformat4c46d092018-04-07 15:32:37414
Paul Lewis9950e182019-12-16 16:06:07415 IncrementBy10:
416 [KeyboardShortcut.makeDescriptor(Keys.PageUp), KeyboardShortcut.makeDescriptor(Keys.Up, Modifiers.Shift)],
Blink Reformat4c46d092018-04-07 15:32:37417
Paul Lewis9950e182019-12-16 16:06:07418 DecrementBy10:
419 [KeyboardShortcut.makeDescriptor(Keys.PageDown), KeyboardShortcut.makeDescriptor(Keys.Down, Modifiers.Shift)],
Blink Reformat4c46d092018-04-07 15:32:37420
Paul Lewis9950e182019-12-16 16:06:07421 IncrementBy100: [KeyboardShortcut.makeDescriptor(Keys.PageUp, Modifiers.Shift)],
Blink Reformat4c46d092018-04-07 15:32:37422
Paul Lewis9950e182019-12-16 16:06:07423 DecrementBy100: [KeyboardShortcut.makeDescriptor(Keys.PageDown, Modifiers.Shift)],
Blink Reformat4c46d092018-04-07 15:32:37424
Paul Lewis9950e182019-12-16 16:06:07425 IncrementBy01: [KeyboardShortcut.makeDescriptor(Keys.Up, Modifiers.Alt)],
Blink Reformat4c46d092018-04-07 15:32:37426
Paul Lewis9950e182019-12-16 16:06:07427 DecrementBy01: [KeyboardShortcut.makeDescriptor(Keys.Down, Modifiers.Alt)]
Blink Reformat4c46d092018-04-07 15:32:37428};
429
Tim van der Lippec96ccd92019-11-29 16:23:54430const ConsolePanelShortcuts = {
Paul Lewis9950e182019-12-16 16:06:07431 AcceptSuggestion: [KeyboardShortcut.makeDescriptor(Keys.Tab), KeyboardShortcut.makeDescriptor(Keys.Right)],
Fabio Rochaf0d95472019-05-28 21:35:19432
Paul Lewis9950e182019-12-16 16:06:07433 ClearConsolePrompt: [KeyboardShortcut.makeDescriptor('u', Modifiers.Ctrl)],
Fabio Rochaf0d95472019-05-28 21:35:19434
Paul Lewis9950e182019-12-16 16:06:07435 ExecuteCommand: KeyboardShortcut.makeDescriptor(Keys.Enter),
Fabio Rochaf0d95472019-05-28 21:35:19436
Paul Lewis9950e182019-12-16 16:06:07437 NextPreviousLine: [KeyboardShortcut.makeDescriptor(Keys.Down), KeyboardShortcut.makeDescriptor(Keys.Up)],
Fabio Rochaf0d95472019-05-28 21:35:19438
Paul Lewis9950e182019-12-16 16:06:07439 NextPreviousCommand:
440 [KeyboardShortcut.makeDescriptor('N', Modifiers.Alt), KeyboardShortcut.makeDescriptor('P', Modifiers.Alt)],
Fabio Rochaf0d95472019-05-28 21:35:19441};
442
Tim van der Lippe0830b3d2019-10-03 13:20:07443export const SourcesPanelShortcuts = {
Paul Lewis9950e182019-12-16 16:06:07444 SelectNextOccurrence: [KeyboardShortcut.makeDescriptor('d', Modifiers.CtrlOrMeta)],
Blink Reformat4c46d092018-04-07 15:32:37445
Paul Lewis9950e182019-12-16 16:06:07446 SoftUndo: [KeyboardShortcut.makeDescriptor('u', Modifiers.CtrlOrMeta)],
Blink Reformat4c46d092018-04-07 15:32:37447
Paul Lewis9950e182019-12-16 16:06:07448 GotoMatchingBracket: [KeyboardShortcut.makeDescriptor('m', Modifiers.Ctrl)],
Blink Reformat4c46d092018-04-07 15:32:37449
Paul Lewis9950e182019-12-16 16:06:07450 ToggleAutocompletion: [KeyboardShortcut.makeDescriptor(Keys.Space, Modifiers.Ctrl)],
Blink Reformat4c46d092018-04-07 15:32:37451
Paul Lewis9950e182019-12-16 16:06:07452 IncreaseCSSUnitByOne: [KeyboardShortcut.makeDescriptor(Keys.Up, Modifiers.Alt)],
Blink Reformat4c46d092018-04-07 15:32:37453
Paul Lewis9950e182019-12-16 16:06:07454 DecreaseCSSUnitByOne: [KeyboardShortcut.makeDescriptor(Keys.Down, Modifiers.Alt)],
Blink Reformat4c46d092018-04-07 15:32:37455
Paul Lewis9950e182019-12-16 16:06:07456 IncreaseCSSUnitByTen: [KeyboardShortcut.makeDescriptor(Keys.PageUp, Modifiers.Alt)],
Blink Reformat4c46d092018-04-07 15:32:37457
Paul Lewis9950e182019-12-16 16:06:07458 DecreaseCSSUnitByTen: [KeyboardShortcut.makeDescriptor(Keys.PageDown, Modifiers.Alt)],
459 EvaluateSelectionInConsole: [KeyboardShortcut.makeDescriptor('e', Modifiers.Shift | Modifiers.Ctrl)],
Blink Reformat4c46d092018-04-07 15:32:37460
Paul Lewis9950e182019-12-16 16:06:07461 AddSelectionToWatch: [KeyboardShortcut.makeDescriptor('a', Modifiers.Shift | Modifiers.Ctrl)],
Blink Reformat4c46d092018-04-07 15:32:37462
Paul Lewis9950e182019-12-16 16:06:07463 ToggleComment: [KeyboardShortcut.makeDescriptor(Keys.Slash, Modifiers.CtrlOrMeta)],
Blink Reformat4c46d092018-04-07 15:32:37464};
465
Tim van der Lippe0830b3d2019-10-03 13:20:07466export const LayersPanelShortcuts = {
Paul Lewis9950e182019-12-16 16:06:07467 ResetView: [KeyboardShortcut.makeDescriptor('0')],
Blink Reformat4c46d092018-04-07 15:32:37468
Paul Lewis9950e182019-12-16 16:06:07469 PanMode: [KeyboardShortcut.makeDescriptor('x')],
Blink Reformat4c46d092018-04-07 15:32:37470
Paul Lewis9950e182019-12-16 16:06:07471 RotateMode: [KeyboardShortcut.makeDescriptor('v')],
Blink Reformat4c46d092018-04-07 15:32:37472
Paul Lewis9950e182019-12-16 16:06:07473 TogglePanRotate: [KeyboardShortcut.makeDescriptor(Keys.Shift)],
Blink Reformat4c46d092018-04-07 15:32:37474
Paul Lewis9950e182019-12-16 16:06:07475 ZoomIn:
476 [KeyboardShortcut.makeDescriptor(Keys.Plus, Modifiers.Shift), KeyboardShortcut.makeDescriptor(Keys.NumpadPlus)],
Blink Reformat4c46d092018-04-07 15:32:37477
Paul Lewis9950e182019-12-16 16:06:07478 ZoomOut:
479 [KeyboardShortcut.makeDescriptor(Keys.Minus, Modifiers.Shift), KeyboardShortcut.makeDescriptor(Keys.NumpadMinus)],
Blink Reformat4c46d092018-04-07 15:32:37480
Paul Lewis9950e182019-12-16 16:06:07481 Up: [KeyboardShortcut.makeDescriptor(Keys.Up), KeyboardShortcut.makeDescriptor('w')],
Blink Reformat4c46d092018-04-07 15:32:37482
Paul Lewis9950e182019-12-16 16:06:07483 Down: [KeyboardShortcut.makeDescriptor(Keys.Down), KeyboardShortcut.makeDescriptor('s')],
Blink Reformat4c46d092018-04-07 15:32:37484
Paul Lewis9950e182019-12-16 16:06:07485 Left: [KeyboardShortcut.makeDescriptor(Keys.Left), KeyboardShortcut.makeDescriptor('a')],
Blink Reformat4c46d092018-04-07 15:32:37486
Paul Lewis9950e182019-12-16 16:06:07487 Right: [KeyboardShortcut.makeDescriptor(Keys.Right), KeyboardShortcut.makeDescriptor('d')]
Blink Reformat4c46d092018-04-07 15:32:37488};