blob: c7b5b1b0708c5620c9a7280f959072f879d1771b [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 Lewis9950e182019-12-16 16:06:0731import {KeyboardShortcut, Keys, Modifiers} from './KeyboardShortcut.js';
32import {createDocumentationLink} from './UIUtils.js';
33import {Widget} from './Widget.js';
34
Blink Reformat4c46d092018-04-07 15:32:3735/**
36 * @unrestricted
37 */
Paul Lewis9950e182019-12-16 16:06:0738export class ShortcutsScreen {
Blink Reformat4c46d092018-04-07 15:32:3739 constructor() {
Tim van der Lippe0830b3d2019-10-03 13:20:0740 /** @type {!Object.<string, !ShortcutsSection>} */
Blink Reformat4c46d092018-04-07 15:32:3741 this._sections = {};
42 }
43
44 static registerShortcuts() {
45 // Elements panel
46 const elementsSection = UI.shortcutsScreen.section(Common.UIString('Elements Panel'));
47
Tim van der Lippe0830b3d2019-10-03 13:20:0748 const navigate = ElementsPanelShortcuts.NavigateUp.concat(ElementsPanelShortcuts.NavigateDown);
Blink Reformat4c46d092018-04-07 15:32:3749 elementsSection.addRelatedKeys(navigate, Common.UIString('Navigate elements'));
50
Tim van der Lippe0830b3d2019-10-03 13:20:0751 const expandCollapse = ElementsPanelShortcuts.Expand.concat(ElementsPanelShortcuts.Collapse);
Blink Reformat4c46d092018-04-07 15:32:3752 elementsSection.addRelatedKeys(expandCollapse, Common.UIString('Expand/collapse'));
53
Tim van der Lippe0830b3d2019-10-03 13:20:0754 elementsSection.addAlternateKeys(ElementsPanelShortcuts.EditAttribute, Common.UIString('Edit attribute'));
Blink Reformat4c46d092018-04-07 15:32:3755 elementsSection.addAlternateKeys(
Joel Einbindera66e5bf2018-05-31 01:26:3756 UI.shortcutRegistry.shortcutDescriptorsForAction('elements.hide-element'), Common.UIString('Hide element'));
Blink Reformat4c46d092018-04-07 15:32:3757 elementsSection.addAlternateKeys(
Joel Einbindera66e5bf2018-05-31 01:26:3758 UI.shortcutRegistry.shortcutDescriptorsForAction('elements.edit-as-html'),
59 Common.UIString('Toggle edit as HTML'));
Blink Reformat4c46d092018-04-07 15:32:3760
Fabio Rochaf0d95472019-05-28 21:35:1961 // Styles pane
Blink Reformat4c46d092018-04-07 15:32:3762 const stylesPaneSection = UI.shortcutsScreen.section(Common.UIString('Styles Pane'));
63
Tim van der Lippe0830b3d2019-10-03 13:20:0764 const nextPreviousProperty = ElementsPanelShortcuts.NextProperty.concat(ElementsPanelShortcuts.PreviousProperty);
Blink Reformat4c46d092018-04-07 15:32:3765 stylesPaneSection.addRelatedKeys(nextPreviousProperty, Common.UIString('Next/previous property'));
66
Tim van der Lippe0830b3d2019-10-03 13:20:0767 stylesPaneSection.addRelatedKeys(ElementsPanelShortcuts.IncrementValue, Common.UIString('Increment value'));
68 stylesPaneSection.addRelatedKeys(ElementsPanelShortcuts.DecrementValue, Common.UIString('Decrement value'));
Blink Reformat4c46d092018-04-07 15:32:3769
Tim van der Lippe0830b3d2019-10-03 13:20:0770 stylesPaneSection.addAlternateKeys(ElementsPanelShortcuts.IncrementBy10, Common.UIString('Increment by %f', 10));
71 stylesPaneSection.addAlternateKeys(ElementsPanelShortcuts.DecrementBy10, Common.UIString('Decrement by %f', 10));
Blink Reformat4c46d092018-04-07 15:32:3772
Tim van der Lippe0830b3d2019-10-03 13:20:0773 stylesPaneSection.addAlternateKeys(ElementsPanelShortcuts.IncrementBy100, Common.UIString('Increment by %f', 100));
74 stylesPaneSection.addAlternateKeys(ElementsPanelShortcuts.DecrementBy100, Common.UIString('Decrement by %f', 100));
Blink Reformat4c46d092018-04-07 15:32:3775
Tim van der Lippe0830b3d2019-10-03 13:20:0776 stylesPaneSection.addAlternateKeys(ElementsPanelShortcuts.IncrementBy01, Common.UIString('Increment by %f', 0.1));
77 stylesPaneSection.addAlternateKeys(ElementsPanelShortcuts.DecrementBy01, Common.UIString('Decrement by %f', 0.1));
Blink Reformat4c46d092018-04-07 15:32:3778
Fabio Rochaf0d95472019-05-28 21:35:1979 // Console
80 const consoleSection = UI.shortcutsScreen.section(Common.UIString('Console'));
Blink Reformat4c46d092018-04-07 15:32:3781
Fabio Rochaf0d95472019-05-28 21:35:1982 consoleSection.addAlternateKeys(
83 UI.shortcutRegistry.shortcutDescriptorsForAction('console.clear'), Common.UIString('Clear console'));
Tim van der Lippe0830b3d2019-10-03 13:20:0784 consoleSection.addRelatedKeys(ConsolePanelShortcuts.AcceptSuggestion, Common.UIString('Accept suggestion'));
85 consoleSection.addAlternateKeys(ConsolePanelShortcuts.ClearConsolePrompt, Common.UIString('Clear console prompt'));
86 consoleSection.addRelatedKeys(ConsolePanelShortcuts.NextPreviousLine, Common.UIString('Next/previous line'));
Fabio Rochaf0d95472019-05-28 21:35:1987
88 if (Host.isMac()) {
89 consoleSection.addRelatedKeys(
Tim van der Lippe0830b3d2019-10-03 13:20:0790 ConsolePanelShortcuts.NextPreviousCommand, Common.UIString('Next/previous command'));
Fabio Rochaf0d95472019-05-28 21:35:1991 }
92
Tim van der Lippe0830b3d2019-10-03 13:20:0793 consoleSection.addKey(ConsolePanelShortcuts.ExecuteCommand, Common.UIString('Execute command'));
Fabio Rochaf0d95472019-05-28 21:35:1994
95 // Debugger
96 const debuggerSection = UI.shortcutsScreen.section(Common.UIString('Debugger'));
97
98 debuggerSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:3799 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-pause'), Common.UIString('Pause/ Continue'));
Fabio Rochaf0d95472019-05-28 21:35:19100 debuggerSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37101 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.step-over'), Common.UIString('Step over'));
Fabio Rochaf0d95472019-05-28 21:35:19102 debuggerSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37103 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.step-into'), Common.UIString('Step into'));
Fabio Rochaf0d95472019-05-28 21:35:19104 debuggerSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37105 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.step-out'), Common.UIString('Step out'));
106
107 const nextAndPrevFrameKeys =
108 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.next-call-frame')
109 .concat(UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.previous-call-frame'));
Fabio Rochaf0d95472019-05-28 21:35:19110 debuggerSection.addRelatedKeys(nextAndPrevFrameKeys, Common.UIString('Next/previous call frame'));
Blink Reformat4c46d092018-04-07 15:32:37111
Fabio Rochaf0d95472019-05-28 21:35:19112 debuggerSection.addAlternateKeys(
Tim van der Lippe0830b3d2019-10-03 13:20:07113 SourcesPanelShortcuts.EvaluateSelectionInConsole, Common.UIString('Evaluate selection in console'));
Fabio Rochaf0d95472019-05-28 21:35:19114 debuggerSection.addAlternateKeys(
Tim van der Lippe0830b3d2019-10-03 13:20:07115 SourcesPanelShortcuts.AddSelectionToWatch, Common.UIString('Add selection to watch'));
Fabio Rochaf0d95472019-05-28 21:35:19116 debuggerSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37117 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-breakpoint'),
118 Common.UIString('Toggle breakpoint'));
Fabio Rochaf0d95472019-05-28 21:35:19119 debuggerSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37120 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-breakpoint-enabled'),
121 Common.UIString('Toggle breakpoint enabled'));
Fabio Rochaf0d95472019-05-28 21:35:19122 debuggerSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37123 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-breakpoints-active'),
124 Common.UIString('Toggle all breakpoints'));
Olivia Flynn8e746e02019-06-19 17:06:23125 debuggerSection.addAlternateKeys(
126 UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.breakpoint-input-window'),
127 ls`Open breakpoint editor`);
Blink Reformat4c46d092018-04-07 15:32:37128
129 // Editing
Fabio Rochaf0d95472019-05-28 21:35:19130 const editingSection = UI.shortcutsScreen.section(Common.UIString('Text Editor'));
131
132 editingSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37133 UI.shortcutRegistry.shortcutDescriptorsForAction('sources.go-to-member'), Common.UIString('Go to member'));
Tim van der Lippe0830b3d2019-10-03 13:20:07134 editingSection.addAlternateKeys(SourcesPanelShortcuts.ToggleAutocompletion, Common.UIString('Autocompletion'));
Fabio Rochaf0d95472019-05-28 21:35:19135 editingSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37136 UI.shortcutRegistry.shortcutDescriptorsForAction('sources.go-to-line'), Common.UIString('Go to line'));
Fabio Rochaf0d95472019-05-28 21:35:19137 editingSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37138 UI.shortcutRegistry.shortcutDescriptorsForAction('sources.jump-to-previous-location'),
139 Common.UIString('Jump to previous editing location'));
Fabio Rochaf0d95472019-05-28 21:35:19140 editingSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37141 UI.shortcutRegistry.shortcutDescriptorsForAction('sources.jump-to-next-location'),
142 Common.UIString('Jump to next editing location'));
Tim van der Lippe0830b3d2019-10-03 13:20:07143 editingSection.addAlternateKeys(SourcesPanelShortcuts.ToggleComment, Common.UIString('Toggle comment'));
Fabio Rochaf0d95472019-05-28 21:35:19144 editingSection.addAlternateKeys(
Tim van der Lippe0830b3d2019-10-03 13:20:07145 SourcesPanelShortcuts.IncreaseCSSUnitByOne, Common.UIString('Increment CSS unit by 1'));
Fabio Rochaf0d95472019-05-28 21:35:19146 editingSection.addAlternateKeys(
Tim van der Lippe0830b3d2019-10-03 13:20:07147 SourcesPanelShortcuts.DecreaseCSSUnitByOne, Common.UIString('Decrement CSS unit by 1'));
Fabio Rochaf0d95472019-05-28 21:35:19148 editingSection.addAlternateKeys(
Tim van der Lippe0830b3d2019-10-03 13:20:07149 SourcesPanelShortcuts.IncreaseCSSUnitByTen, Common.UIString('Increment CSS unit by 10'));
Fabio Rochaf0d95472019-05-28 21:35:19150 editingSection.addAlternateKeys(
Tim van der Lippe0830b3d2019-10-03 13:20:07151 SourcesPanelShortcuts.DecreaseCSSUnitByTen, Common.UIString('Decrement CSS unit by 10'));
Fabio Rochaf0d95472019-05-28 21:35:19152 editingSection.addAlternateKeys(
Tim van der Lippe0830b3d2019-10-03 13:20:07153 SourcesPanelShortcuts.SelectNextOccurrence, Common.UIString('Select next occurrence'));
154 editingSection.addAlternateKeys(SourcesPanelShortcuts.SoftUndo, Common.UIString('Soft undo'));
Fabio Rochaf0d95472019-05-28 21:35:19155 editingSection.addAlternateKeys(
Tim van der Lippe0830b3d2019-10-03 13:20:07156 SourcesPanelShortcuts.GotoMatchingBracket, Common.UIString('Go to matching bracket'));
Fabio Rochaf0d95472019-05-28 21:35:19157 editingSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37158 UI.shortcutRegistry.shortcutDescriptorsForAction('sources.close-editor-tab'),
159 Common.UIString('Close editor tab'));
Fabio Rochaf0d95472019-05-28 21:35:19160 editingSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37161 UI.shortcutRegistry.shortcutDescriptorsForAction('sources.switch-file'),
162 Common.UIString('Switch between files with the same name and different extensions.'));
163
164 // Performance panel
Fabio Rochaf0d95472019-05-28 21:35:19165 const performanceSection = UI.shortcutsScreen.section(Common.UIString('Performance Panel'));
166
167 performanceSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37168 UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.toggle-recording'),
169 Common.UIString('Start/stop recording'));
Fabio Rochaf0d95472019-05-28 21:35:19170 performanceSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37171 UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.record-reload'),
172 Common.UIString('Record page reload'));
Fabio Rochaf0d95472019-05-28 21:35:19173 performanceSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37174 UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.save-to-file'), Common.UIString('Save profile'));
Fabio Rochaf0d95472019-05-28 21:35:19175 performanceSection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37176 UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.load-from-file'), Common.UIString('Load profile'));
Fabio Rochaf0d95472019-05-28 21:35:19177 performanceSection.addRelatedKeys(
Blink Reformat4c46d092018-04-07 15:32:37178 UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.jump-to-previous-frame')
179 .concat(UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.jump-to-next-frame')),
180 Common.UIString('Jump to previous/next frame'));
Fabio Rochaf0d95472019-05-28 21:35:19181 performanceSection.addRelatedKeys(
Blink Reformat4c46d092018-04-07 15:32:37182 UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.show-history'),
183 Common.UIString('Pick a recording from history'));
Fabio Rochaf0d95472019-05-28 21:35:19184 performanceSection.addRelatedKeys(
Blink Reformat4c46d092018-04-07 15:32:37185 UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.previous-recording')
186 .concat(UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.next-recording')),
187 Common.UIString('Show previous/next recording'));
188
189 // Memory panel
Fabio Rochaf0d95472019-05-28 21:35:19190 const memorySection = UI.shortcutsScreen.section(Common.UIString('Memory Panel'));
191
192 memorySection.addAlternateKeys(
Blink Reformat4c46d092018-04-07 15:32:37193 UI.shortcutRegistry.shortcutDescriptorsForAction('profiler.heap-toggle-recording'),
194 Common.UIString('Start/stop recording'));
195
196 // Layers panel
Fabio Rochaf0d95472019-05-28 21:35:19197 const layersSection = UI.shortcutsScreen.section(Common.UIString('Layers Panel'));
198
Tim van der Lippe0830b3d2019-10-03 13:20:07199 layersSection.addAlternateKeys(LayersPanelShortcuts.ResetView, Common.UIString('Reset view'));
200 layersSection.addAlternateKeys(LayersPanelShortcuts.PanMode, Common.UIString('Switch to pan mode'));
201 layersSection.addAlternateKeys(LayersPanelShortcuts.RotateMode, Common.UIString('Switch to rotate mode'));
Fabio Rochaf0d95472019-05-28 21:35:19202 layersSection.addAlternateKeys(
Tim van der Lippe0830b3d2019-10-03 13:20:07203 LayersPanelShortcuts.TogglePanRotate, Common.UIString('Temporarily toggle pan/rotate mode while held'));
204 layersSection.addAlternateKeys(LayersPanelShortcuts.ZoomIn, Common.UIString('Zoom in'));
205 layersSection.addAlternateKeys(LayersPanelShortcuts.ZoomOut, Common.UIString('Zoom out'));
Fabio Rochaf0d95472019-05-28 21:35:19206 layersSection.addRelatedKeys(
Tim van der Lippe0830b3d2019-10-03 13:20:07207 LayersPanelShortcuts.Up.concat(LayersPanelShortcuts.Down), Common.UIString('Pan or rotate up/down'));
Fabio Rochaf0d95472019-05-28 21:35:19208 layersSection.addRelatedKeys(
Tim van der Lippe0830b3d2019-10-03 13:20:07209 LayersPanelShortcuts.Left.concat(LayersPanelShortcuts.Right), Common.UIString('Pan or rotate left/right'));
Blink Reformat4c46d092018-04-07 15:32:37210 }
211
212 /**
213 * @param {string} name
Tim van der Lippe0830b3d2019-10-03 13:20:07214 * @return {!ShortcutsSection}
Blink Reformat4c46d092018-04-07 15:32:37215 */
216 section(name) {
217 let section = this._sections[name];
Tim van der Lippe1d6e57a2019-09-30 11:55:34218 if (!section) {
Tim van der Lippe0830b3d2019-10-03 13:20:07219 this._sections[name] = section = new ShortcutsSection(name);
Tim van der Lippe1d6e57a2019-09-30 11:55:34220 }
Blink Reformat4c46d092018-04-07 15:32:37221 return section;
222 }
223
224 /**
Paul Lewis9950e182019-12-16 16:06:07225 * @return {!Widget}
Blink Reformat4c46d092018-04-07 15:32:37226 */
227 createShortcutsTabView() {
228 const orderedSections = [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34229 for (const section in this._sections) {
Blink Reformat4c46d092018-04-07 15:32:37230 orderedSections.push(this._sections[section]);
Tim van der Lippe1d6e57a2019-09-30 11:55:34231 }
Blink Reformat4c46d092018-04-07 15:32:37232 function compareSections(a, b) {
233 return a.order - b.order;
234 }
235 orderedSections.sort(compareSections);
236
Paul Lewis9950e182019-12-16 16:06:07237 const widget = new Widget();
Blink Reformat4c46d092018-04-07 15:32:37238
239 widget.element.className = 'settings-tab-container'; // Override
Chandani Shrestha83bd7c92019-06-11 21:21:59240 widget.element.createChild('header').createChild('h1').createTextChild(ls`Shortcuts`);
Blink Reformat4c46d092018-04-07 15:32:37241 const scrollPane = widget.element.createChild('div', 'settings-container-wrapper');
242 const container = scrollPane.createChild('div');
243 container.className = 'settings-content settings-container';
Tim van der Lippe1d6e57a2019-09-30 11:55:34244 for (let i = 0; i < orderedSections.length; ++i) {
Blink Reformat4c46d092018-04-07 15:32:37245 orderedSections[i].renderSection(container);
Tim van der Lippe1d6e57a2019-09-30 11:55:34246 }
Blink Reformat4c46d092018-04-07 15:32:37247
248 const note = scrollPane.createChild('p', 'settings-footnote');
Paul Lewis9950e182019-12-16 16:06:07249 note.appendChild(createDocumentationLink(
Blink Reformat4c46d092018-04-07 15:32:37250 'iterate/inspect-styles/shortcuts', Common.UIString('Full list of DevTools keyboard shortcuts and gestures')));
251
252 return widget;
253 }
Tim van der Lippe0830b3d2019-10-03 13:20:07254}
Blink Reformat4c46d092018-04-07 15:32:37255
256/**
Blink Reformat4c46d092018-04-07 15:32:37257 * @unrestricted
258 */
Tim van der Lippec96ccd92019-11-29 16:23:54259class ShortcutsSection {
Blink Reformat4c46d092018-04-07 15:32:37260 /**
261 * @param {string} name
262 */
263 constructor(name) {
264 this.name = name;
265 this._lines = /** @type {!Array.<!{key: !Node, text: string}>} */ ([]);
Tim van der Lippe0830b3d2019-10-03 13:20:07266 this.order = ++ShortcutsSection._sequenceNumber;
Blink Reformat4c46d092018-04-07 15:32:37267 }
268
269 /**
270 * @param {!UI.KeyboardShortcut.Descriptor} key
271 * @param {string} description
272 */
273 addKey(key, description) {
274 this._addLine(this._renderKey(key), description);
275 }
276
277 /**
278 * @param {!Array.<!UI.KeyboardShortcut.Descriptor>} keys
279 * @param {string} description
280 */
281 addRelatedKeys(keys, description) {
282 this._addLine(this._renderSequence(keys, '/'), description);
283 }
284
285 /**
286 * @param {!Array.<!UI.KeyboardShortcut.Descriptor>} keys
287 * @param {string} description
288 */
289 addAlternateKeys(keys, description) {
290 this._addLine(this._renderSequence(keys, Common.UIString('or')), description);
291 }
292
293 /**
294 * @param {!Node} keyElement
295 * @param {string} description
296 */
297 _addLine(keyElement, description) {
298 this._lines.push({key: keyElement, text: description});
299 }
300
301 /**
302 * @param {!Element} container
303 */
304 renderSection(container) {
305 const parent = container.createChild('div', 'settings-block');
306
307 const headLine = parent.createChild('div', 'settings-line');
308 headLine.createChild('div', 'settings-key-cell');
309 headLine.createChild('div', 'settings-section-title settings-cell').textContent = this.name;
Amanda Baker11630de2019-07-12 02:54:33310 UI.ARIAUtils.markAsHeading(headLine, /* level */ 2);
Blink Reformat4c46d092018-04-07 15:32:37311
312 for (let i = 0; i < this._lines.length; ++i) {
313 const line = parent.createChild('div', 'settings-line');
314 const keyCell = line.createChild('div', 'settings-key-cell');
315 keyCell.appendChild(this._lines[i].key);
316 keyCell.appendChild(this._createSpan('settings-key-delimiter', ':'));
317 line.createChild('div', 'settings-cell').textContent = this._lines[i].text;
318 }
319 }
320
321 /**
322 * @param {!Array.<!UI.KeyboardShortcut.Descriptor>} sequence
323 * @param {string} delimiter
324 * @return {!Node}
325 */
326 _renderSequence(sequence, delimiter) {
327 const delimiterSpan = this._createSpan('settings-key-delimiter', delimiter);
328 return this._joinNodes(sequence.map(this._renderKey.bind(this)), delimiterSpan);
329 }
330
331 /**
332 * @param {!UI.KeyboardShortcut.Descriptor} key
333 * @return {!Node}
334 */
335 _renderKey(key) {
336 const keyName = key.name;
337 const plus = this._createSpan('settings-combine-keys', '+');
338 return this._joinNodes(keyName.split(' + ').map(this._createSpan.bind(this, 'settings-key')), plus);
339 }
340
341 /**
342 * @param {string} className
343 * @param {string} textContent
344 * @return {!Element}
345 */
346 _createSpan(className, textContent) {
347 const node = createElement('span');
348 node.className = className;
349 node.textContent = textContent;
350 return node;
351 }
352
353 /**
354 * @param {!Array.<!Element>} nodes
355 * @param {!Element} delimiter
356 * @return {!Node}
357 */
358 _joinNodes(nodes, delimiter) {
359 const result = createDocumentFragment();
360 for (let i = 0; i < nodes.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34361 if (i > 0) {
Blink Reformat4c46d092018-04-07 15:32:37362 result.appendChild(delimiter.cloneNode(true));
Tim van der Lippe1d6e57a2019-09-30 11:55:34363 }
Blink Reformat4c46d092018-04-07 15:32:37364 result.appendChild(nodes[i]);
365 }
366 return result;
367 }
Tim van der Lippe0830b3d2019-10-03 13:20:07368}
Blink Reformat4c46d092018-04-07 15:32:37369
Tim van der Lippe0830b3d2019-10-03 13:20:07370ShortcutsSection._sequenceNumber = 0;
Blink Reformat4c46d092018-04-07 15:32:37371
372
Tim van der Lippec96ccd92019-11-29 16:23:54373const ElementsPanelShortcuts = {
Paul Lewis9950e182019-12-16 16:06:07374 NavigateUp: [KeyboardShortcut.makeDescriptor(Keys.Up)],
Blink Reformat4c46d092018-04-07 15:32:37375
Paul Lewis9950e182019-12-16 16:06:07376 NavigateDown: [KeyboardShortcut.makeDescriptor(Keys.Down)],
Blink Reformat4c46d092018-04-07 15:32:37377
Paul Lewis9950e182019-12-16 16:06:07378 Expand: [KeyboardShortcut.makeDescriptor(Keys.Right)],
Blink Reformat4c46d092018-04-07 15:32:37379
Paul Lewis9950e182019-12-16 16:06:07380 Collapse: [KeyboardShortcut.makeDescriptor(Keys.Left)],
Blink Reformat4c46d092018-04-07 15:32:37381
Paul Lewis9950e182019-12-16 16:06:07382 EditAttribute: [KeyboardShortcut.makeDescriptor(Keys.Enter)],
Blink Reformat4c46d092018-04-07 15:32:37383
Paul Lewis9950e182019-12-16 16:06:07384 NextProperty: [KeyboardShortcut.makeDescriptor(Keys.Tab)],
Blink Reformat4c46d092018-04-07 15:32:37385
Paul Lewis9950e182019-12-16 16:06:07386 PreviousProperty: [KeyboardShortcut.makeDescriptor(Keys.Tab, Modifiers.Shift)],
Blink Reformat4c46d092018-04-07 15:32:37387
Paul Lewis9950e182019-12-16 16:06:07388 IncrementValue: [KeyboardShortcut.makeDescriptor(Keys.Up)],
Blink Reformat4c46d092018-04-07 15:32:37389
Paul Lewis9950e182019-12-16 16:06:07390 DecrementValue: [KeyboardShortcut.makeDescriptor(Keys.Down)],
Blink Reformat4c46d092018-04-07 15:32:37391
Paul Lewis9950e182019-12-16 16:06:07392 IncrementBy10:
393 [KeyboardShortcut.makeDescriptor(Keys.PageUp), KeyboardShortcut.makeDescriptor(Keys.Up, Modifiers.Shift)],
Blink Reformat4c46d092018-04-07 15:32:37394
Paul Lewis9950e182019-12-16 16:06:07395 DecrementBy10:
396 [KeyboardShortcut.makeDescriptor(Keys.PageDown), KeyboardShortcut.makeDescriptor(Keys.Down, Modifiers.Shift)],
Blink Reformat4c46d092018-04-07 15:32:37397
Paul Lewis9950e182019-12-16 16:06:07398 IncrementBy100: [KeyboardShortcut.makeDescriptor(Keys.PageUp, Modifiers.Shift)],
Blink Reformat4c46d092018-04-07 15:32:37399
Paul Lewis9950e182019-12-16 16:06:07400 DecrementBy100: [KeyboardShortcut.makeDescriptor(Keys.PageDown, Modifiers.Shift)],
Blink Reformat4c46d092018-04-07 15:32:37401
Paul Lewis9950e182019-12-16 16:06:07402 IncrementBy01: [KeyboardShortcut.makeDescriptor(Keys.Up, Modifiers.Alt)],
Blink Reformat4c46d092018-04-07 15:32:37403
Paul Lewis9950e182019-12-16 16:06:07404 DecrementBy01: [KeyboardShortcut.makeDescriptor(Keys.Down, Modifiers.Alt)]
Blink Reformat4c46d092018-04-07 15:32:37405};
406
Tim van der Lippec96ccd92019-11-29 16:23:54407const ConsolePanelShortcuts = {
Paul Lewis9950e182019-12-16 16:06:07408 AcceptSuggestion: [KeyboardShortcut.makeDescriptor(Keys.Tab), KeyboardShortcut.makeDescriptor(Keys.Right)],
Fabio Rochaf0d95472019-05-28 21:35:19409
Paul Lewis9950e182019-12-16 16:06:07410 ClearConsolePrompt: [KeyboardShortcut.makeDescriptor('u', Modifiers.Ctrl)],
Fabio Rochaf0d95472019-05-28 21:35:19411
Paul Lewis9950e182019-12-16 16:06:07412 ExecuteCommand: KeyboardShortcut.makeDescriptor(Keys.Enter),
Fabio Rochaf0d95472019-05-28 21:35:19413
Paul Lewis9950e182019-12-16 16:06:07414 NextPreviousLine: [KeyboardShortcut.makeDescriptor(Keys.Down), KeyboardShortcut.makeDescriptor(Keys.Up)],
Fabio Rochaf0d95472019-05-28 21:35:19415
Paul Lewis9950e182019-12-16 16:06:07416 NextPreviousCommand:
417 [KeyboardShortcut.makeDescriptor('N', Modifiers.Alt), KeyboardShortcut.makeDescriptor('P', Modifiers.Alt)],
Fabio Rochaf0d95472019-05-28 21:35:19418};
419
Tim van der Lippe0830b3d2019-10-03 13:20:07420export const SourcesPanelShortcuts = {
Paul Lewis9950e182019-12-16 16:06:07421 SelectNextOccurrence: [KeyboardShortcut.makeDescriptor('d', Modifiers.CtrlOrMeta)],
Blink Reformat4c46d092018-04-07 15:32:37422
Paul Lewis9950e182019-12-16 16:06:07423 SoftUndo: [KeyboardShortcut.makeDescriptor('u', Modifiers.CtrlOrMeta)],
Blink Reformat4c46d092018-04-07 15:32:37424
Paul Lewis9950e182019-12-16 16:06:07425 GotoMatchingBracket: [KeyboardShortcut.makeDescriptor('m', Modifiers.Ctrl)],
Blink Reformat4c46d092018-04-07 15:32:37426
Paul Lewis9950e182019-12-16 16:06:07427 ToggleAutocompletion: [KeyboardShortcut.makeDescriptor(Keys.Space, Modifiers.Ctrl)],
Blink Reformat4c46d092018-04-07 15:32:37428
Paul Lewis9950e182019-12-16 16:06:07429 IncreaseCSSUnitByOne: [KeyboardShortcut.makeDescriptor(Keys.Up, Modifiers.Alt)],
Blink Reformat4c46d092018-04-07 15:32:37430
Paul Lewis9950e182019-12-16 16:06:07431 DecreaseCSSUnitByOne: [KeyboardShortcut.makeDescriptor(Keys.Down, Modifiers.Alt)],
Blink Reformat4c46d092018-04-07 15:32:37432
Paul Lewis9950e182019-12-16 16:06:07433 IncreaseCSSUnitByTen: [KeyboardShortcut.makeDescriptor(Keys.PageUp, Modifiers.Alt)],
Blink Reformat4c46d092018-04-07 15:32:37434
Paul Lewis9950e182019-12-16 16:06:07435 DecreaseCSSUnitByTen: [KeyboardShortcut.makeDescriptor(Keys.PageDown, Modifiers.Alt)],
436 EvaluateSelectionInConsole: [KeyboardShortcut.makeDescriptor('e', Modifiers.Shift | Modifiers.Ctrl)],
Blink Reformat4c46d092018-04-07 15:32:37437
Paul Lewis9950e182019-12-16 16:06:07438 AddSelectionToWatch: [KeyboardShortcut.makeDescriptor('a', Modifiers.Shift | Modifiers.Ctrl)],
Blink Reformat4c46d092018-04-07 15:32:37439
Paul Lewis9950e182019-12-16 16:06:07440 ToggleComment: [KeyboardShortcut.makeDescriptor(Keys.Slash, Modifiers.CtrlOrMeta)],
Blink Reformat4c46d092018-04-07 15:32:37441};
442
Tim van der Lippe0830b3d2019-10-03 13:20:07443export const LayersPanelShortcuts = {
Paul Lewis9950e182019-12-16 16:06:07444 ResetView: [KeyboardShortcut.makeDescriptor('0')],
Blink Reformat4c46d092018-04-07 15:32:37445
Paul Lewis9950e182019-12-16 16:06:07446 PanMode: [KeyboardShortcut.makeDescriptor('x')],
Blink Reformat4c46d092018-04-07 15:32:37447
Paul Lewis9950e182019-12-16 16:06:07448 RotateMode: [KeyboardShortcut.makeDescriptor('v')],
Blink Reformat4c46d092018-04-07 15:32:37449
Paul Lewis9950e182019-12-16 16:06:07450 TogglePanRotate: [KeyboardShortcut.makeDescriptor(Keys.Shift)],
Blink Reformat4c46d092018-04-07 15:32:37451
Paul Lewis9950e182019-12-16 16:06:07452 ZoomIn:
453 [KeyboardShortcut.makeDescriptor(Keys.Plus, Modifiers.Shift), KeyboardShortcut.makeDescriptor(Keys.NumpadPlus)],
Blink Reformat4c46d092018-04-07 15:32:37454
Paul Lewis9950e182019-12-16 16:06:07455 ZoomOut:
456 [KeyboardShortcut.makeDescriptor(Keys.Minus, Modifiers.Shift), KeyboardShortcut.makeDescriptor(Keys.NumpadMinus)],
Blink Reformat4c46d092018-04-07 15:32:37457
Paul Lewis9950e182019-12-16 16:06:07458 Up: [KeyboardShortcut.makeDescriptor(Keys.Up), KeyboardShortcut.makeDescriptor('w')],
Blink Reformat4c46d092018-04-07 15:32:37459
Paul Lewis9950e182019-12-16 16:06:07460 Down: [KeyboardShortcut.makeDescriptor(Keys.Down), KeyboardShortcut.makeDescriptor('s')],
Blink Reformat4c46d092018-04-07 15:32:37461
Paul Lewis9950e182019-12-16 16:06:07462 Left: [KeyboardShortcut.makeDescriptor(Keys.Left), KeyboardShortcut.makeDescriptor('a')],
Blink Reformat4c46d092018-04-07 15:32:37463
Paul Lewis9950e182019-12-16 16:06:07464 Right: [KeyboardShortcut.makeDescriptor(Keys.Right), KeyboardShortcut.makeDescriptor('d')]
Blink Reformat4c46d092018-04-07 15:32:37465};