From 055533e783dcaf9268a3f6849a2974e91537be7d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:17:17 -0700 Subject: [PATCH 1/4] Migrate core/shortcut_registry.js to ES6 const/let --- core/shortcut_registry.js | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index 14684e1b8..807f40d84 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -78,7 +78,7 @@ Blockly.ShortcutRegistry.KeyboardShortcut; */ Blockly.ShortcutRegistry.prototype.register = function( shortcut, opt_allowOverrides) { - var registeredShortcut = this.registry_[shortcut.name]; + const registeredShortcut = this.registry_[shortcut.name]; if (registeredShortcut && !opt_allowOverrides) { throw new Error( 'Shortcut with name "' + shortcut.name + '" already exists.'); @@ -94,7 +94,7 @@ Blockly.ShortcutRegistry.prototype.register = function( * @public */ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { - var shortcut = this.registry_[shortcutName]; + const shortcut = this.registry_[shortcutName]; if (!shortcut) { console.warn( @@ -123,7 +123,7 @@ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { Blockly.ShortcutRegistry.prototype.addKeyMapping = function( keyCode, shortcutName, opt_allowCollision) { keyCode = String(keyCode); - var shortcutNames = this.keyMap_[keyCode]; + const shortcutNames = this.keyMap_[keyCode]; if (shortcutNames && !opt_allowCollision) { throw new Error( 'Shortcut with name "' + shortcutName + '" collides with shortcuts ' + @@ -149,7 +149,7 @@ Blockly.ShortcutRegistry.prototype.addKeyMapping = function( */ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( keyCode, shortcutName, opt_quiet) { - var shortcutNames = this.keyMap_[keyCode]; + const shortcutNames = this.keyMap_[keyCode]; if (!shortcutNames && !opt_quiet) { console.warn( @@ -158,7 +158,7 @@ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( return false; } - var shortcutIdx = shortcutNames.indexOf(shortcutName); + const shortcutIdx = shortcutNames.indexOf(shortcutName); if (shortcutIdx > -1) { shortcutNames.splice(shortcutIdx, 1); if (shortcutNames.length == 0) { @@ -181,7 +181,7 @@ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( * @public */ Blockly.ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { - for (var keyCode in this.keyMap_) { + for (const keyCode in this.keyMap_) { this.removeKeyMapping(keyCode, shortcutName, true); } }; @@ -225,13 +225,13 @@ Blockly.ShortcutRegistry.prototype.getRegistry = function() { * @public */ Blockly.ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { - var key = this.serializeKeyEvent_(e); - var shortcutNames = this.getShortcutNamesByKeyCode(key); + const key = this.serializeKeyEvent_(e); + const shortcutNames = this.getShortcutNamesByKeyCode(key); if (!shortcutNames) { return false; } - for (var i = 0, shortcutName; (shortcutName = shortcutNames[i]); i++) { - var shortcut = this.registry_[shortcutName]; + for (let i = 0, shortcutName; (shortcutName = shortcutNames[i]); i++) { + const shortcut = this.registry_[shortcutName]; if (!shortcut.preconditionFn || shortcut.preconditionFn(workspace)) { // If the key has been handled, stop processing shortcuts. if (shortcut.callback && shortcut.callback(workspace, e, shortcut)) { @@ -264,10 +264,10 @@ Blockly.ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( */ Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( shortcutName) { - var keys = []; - for (var keyCode in this.keyMap_) { - var shortcuts = this.keyMap_[keyCode]; - var shortcutIdx = shortcuts.indexOf(shortcutName); + const keys = []; + for (const keyCode in this.keyMap_) { + const shortcuts = this.keyMap_[keyCode]; + const shortcutIdx = shortcuts.indexOf(shortcutName); if (shortcutIdx > -1) { keys.push(keyCode); } @@ -282,8 +282,8 @@ Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( * @private */ Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { - var serializedKey = ''; - for (var modifier in Blockly.ShortcutRegistry.modifierKeys) { + let serializedKey = ''; + for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { if (e.getModifierState(modifier)) { if (serializedKey != '') { serializedKey += '+'; @@ -307,9 +307,9 @@ Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { */ Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( modifiers) { - var validModifiers = Blockly.utils.object.values( + const validModifiers = Blockly.utils.object.values( Blockly.ShortcutRegistry.modifierKeys); - for (var i = 0, modifier; (modifier = modifiers[i]); i++) { + for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { throw new Error(modifier + ' is not a valid modifier key.'); } @@ -327,12 +327,12 @@ Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( */ Blockly.ShortcutRegistry.prototype.createSerializedKey = function( keyCode, modifiers) { - var serializedKey = ''; + let serializedKey = ''; if (modifiers) { this.checkModifiers_(modifiers); - for (var modifier in Blockly.ShortcutRegistry.modifierKeys) { - var modifierKeyCode = + for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { + const modifierKeyCode = Blockly.ShortcutRegistry.modifierKeys[modifier]; if (modifiers.indexOf(modifierKeyCode) > -1) { if (serializedKey != '') { From 69b900aa4626cf584066a670e22cd8ae4553bc99 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:25:30 -0700 Subject: [PATCH 2/4] Migrate core/shortcut_registry.js to goog.module --- core/interfaces/i_keyboard_accessible.js | 5 +- core/shortcut_registry.js | 71 ++++++++++++------------ tests/deps.js | 2 +- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/core/interfaces/i_keyboard_accessible.js b/core/interfaces/i_keyboard_accessible.js index 8243e67d1..04704a2fe 100644 --- a/core/interfaces/i_keyboard_accessible.js +++ b/core/interfaces/i_keyboard_accessible.js @@ -15,7 +15,7 @@ goog.module('Blockly.IKeyboardAccessible'); goog.module.declareLegacyNamespace(); /* eslint-disable-next-line no-unused-vars */ -const {KeyboardShortcut} = goog.requireType('Blockly.ShortcutRegistry'); +const ShortcutRegistry = goog.requireType('Blockly.ShortcutRegistry'); /** @@ -26,7 +26,8 @@ const IKeyboardAccessible = function() {}; /** * Handles the given keyboard shortcut. - * @param {!KeyboardShortcut} shortcut The shortcut to be handled. + * @param {!ShortcutRegistry.KeyboardShortcut} shortcut The shortcut to be + * handled. * @return {boolean} True if the shortcut has been handled, false otherwise. */ IKeyboardAccessible.prototype.onShortcut; diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index 807f40d84..d75ec9546 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -11,7 +11,8 @@ */ 'use strict'; -goog.provide('Blockly.ShortcutRegistry'); +goog.module('Blockly.ShortcutRegistry'); +goog.module.declareLegacyNamespace(); goog.require('Blockly.utils.KeyCodes'); goog.require('Blockly.utils.object'); @@ -22,16 +23,16 @@ goog.requireType('Blockly.Workspace'); /** * Class for the registry of keyboard shortcuts. This is intended to be a * singleton. You should not create a new instance, and only access this class - * from Blockly.ShortcutRegistry.registry. + * from ShortcutRegistry.registry. * @constructor */ -Blockly.ShortcutRegistry = function() { +const ShortcutRegistry = function() { // Singleton instance should be registered once. - Blockly.ShortcutRegistry.registry = this; + ShortcutRegistry.registry = this; /** * Registry of all keyboard shortcuts, keyed by name of shortcut. - * @type {!Object} + * @type {!Object} * @private */ this.registry_ = Object.create(null); @@ -48,7 +49,7 @@ Blockly.ShortcutRegistry = function() { * Enum of valid modifiers. * @enum {!Blockly.utils.KeyCodes} */ -Blockly.ShortcutRegistry.modifierKeys = { +ShortcutRegistry.modifierKeys = { 'Shift': Blockly.utils.KeyCodes.SHIFT, 'Control': Blockly.utils.KeyCodes.CTRL, 'Alt': Blockly.utils.KeyCodes.ALT, @@ -59,24 +60,24 @@ Blockly.ShortcutRegistry.modifierKeys = { * A keyboard shortcut. * @typedef {{ * callback: ((function(!Blockly.Workspace, Event, - * !Blockly.ShortcutRegistry.KeyboardShortcut):boolean)|undefined), + * !ShortcutRegistry.KeyboardShortcut):boolean)|undefined), * name: string, * preconditionFn: ((function(!Blockly.Workspace):boolean)|undefined), * metadata: (Object|undefined) * }} */ -Blockly.ShortcutRegistry.KeyboardShortcut; +ShortcutRegistry.KeyboardShortcut; /** * Registers a keyboard shortcut. - * @param {!Blockly.ShortcutRegistry.KeyboardShortcut} shortcut The + * @param {!ShortcutRegistry.KeyboardShortcut} shortcut The * shortcut for this key code. * @param {boolean=} opt_allowOverrides True to prevent a warning when * overriding an already registered item. * @throws {Error} if a shortcut with the same name already exists. * @public */ -Blockly.ShortcutRegistry.prototype.register = function( +ShortcutRegistry.prototype.register = function( shortcut, opt_allowOverrides) { const registeredShortcut = this.registry_[shortcut.name]; if (registeredShortcut && !opt_allowOverrides) { @@ -93,7 +94,7 @@ Blockly.ShortcutRegistry.prototype.register = function( * @return {boolean} True if an item was unregistered, false otherwise. * @public */ -Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { +ShortcutRegistry.prototype.unregister = function(shortcutName) { const shortcut = this.registry_[shortcutName]; if (!shortcut) { @@ -112,7 +113,7 @@ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { * Adds a mapping between a keycode and a keyboard shortcut. * @param {string|Blockly.utils.KeyCodes} keyCode The key code for the keyboard * shortcut. If registering a key code with a modifier (ex: ctrl+c) use - * Blockly.ShortcutRegistry.registry.createSerializedKey; + * ShortcutRegistry.registry.createSerializedKey; * @param {string} shortcutName The name of the shortcut to execute when the * given keycode is pressed. * @param {boolean=} opt_allowCollision True to prevent an error when adding a @@ -120,7 +121,7 @@ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) { * @throws {Error} if the given key code is already mapped to a shortcut. * @public */ -Blockly.ShortcutRegistry.prototype.addKeyMapping = function( +ShortcutRegistry.prototype.addKeyMapping = function( keyCode, shortcutName, opt_allowCollision) { keyCode = String(keyCode); const shortcutNames = this.keyMap_[keyCode]; @@ -139,7 +140,7 @@ Blockly.ShortcutRegistry.prototype.addKeyMapping = function( * Removes a mapping between a keycode and a keyboard shortcut. * @param {string} keyCode The key code for the keyboard shortcut. If * registering a key code with a modifier (ex: ctrl+c) use - * Blockly.ShortcutRegistry.registry.createSerializedKey; + * ShortcutRegistry.registry.createSerializedKey; * @param {string} shortcutName The name of the shortcut to execute when the * given keycode is pressed. * @param {boolean=} opt_quiet True to not console warn when there is no @@ -147,7 +148,7 @@ Blockly.ShortcutRegistry.prototype.addKeyMapping = function( * @return {boolean} True if a key mapping was removed, false otherwise. * @public */ -Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( +ShortcutRegistry.prototype.removeKeyMapping = function( keyCode, shortcutName, opt_quiet) { const shortcutNames = this.keyMap_[keyCode]; @@ -180,7 +181,7 @@ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function( * @param {string} shortcutName The name of the shortcut to remove from the key map. * @public */ -Blockly.ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { +ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { for (const keyCode in this.keyMap_) { this.removeKeyMapping(keyCode, shortcutName, true); } @@ -192,27 +193,27 @@ Blockly.ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) * shortcut names. * @public */ -Blockly.ShortcutRegistry.prototype.setKeyMap = function(keyMap) { +ShortcutRegistry.prototype.setKeyMap = function(keyMap) { this.keyMap_ = keyMap; }; /** * Gets the current key map. - * @return {!Object>} - * The object holding key codes to Blockly.ShortcutRegistry.KeyboardShortcut. + * @return {!Object>} + * The object holding key codes to ShortcutRegistry.KeyboardShortcut. * @public */ -Blockly.ShortcutRegistry.prototype.getKeyMap = function() { +ShortcutRegistry.prototype.getKeyMap = function() { return Blockly.utils.object.deepMerge(Object.create(null), this.keyMap_); }; /** * Gets the registry of keyboard shortcuts. - * @return {!Object} + * @return {!Object} * The registry of keyboard shortcuts. * @public */ -Blockly.ShortcutRegistry.prototype.getRegistry = function() { +ShortcutRegistry.prototype.getRegistry = function() { return Blockly.utils.object.deepMerge(Object.create(null), this.registry_); }; @@ -224,7 +225,7 @@ Blockly.ShortcutRegistry.prototype.getRegistry = function() { * @return {boolean} True if the event was handled, false otherwise. * @public */ -Blockly.ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { +ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { const key = this.serializeKeyEvent_(e); const shortcutNames = this.getShortcutNamesByKeyCode(key); if (!shortcutNames) { @@ -249,7 +250,7 @@ Blockly.ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { * given keyCode is used. Undefined if no shortcuts exist. * @public */ -Blockly.ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( +ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( keyCode) { return this.keyMap_[keyCode] || []; }; @@ -262,7 +263,7 @@ Blockly.ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( * registered under. * @public */ -Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( +ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( shortcutName) { const keys = []; for (const keyCode in this.keyMap_) { @@ -281,9 +282,9 @@ Blockly.ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( * @return {string} The serialized key code for the given event. * @private */ -Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { +ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { let serializedKey = ''; - for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { + for (const modifier in ShortcutRegistry.modifierKeys) { if (e.getModifierState(modifier)) { if (serializedKey != '') { serializedKey += '+'; @@ -305,10 +306,10 @@ Blockly.ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { * @throws {Error} if the modifier is not in the valid modifiers list. * @private */ -Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( +ShortcutRegistry.prototype.checkModifiers_ = function( modifiers) { const validModifiers = Blockly.utils.object.values( - Blockly.ShortcutRegistry.modifierKeys); + ShortcutRegistry.modifierKeys); for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { throw new Error(modifier + ' is not a valid modifier key.'); @@ -321,19 +322,19 @@ Blockly.ShortcutRegistry.prototype.checkModifiers_ = function( * @param {number} keyCode Number code representing the key. * @param {?Array} modifiers List of modifier key codes to be used with * the key. All valid modifiers can be found in the - * Blockly.ShortcutRegistry.modifierKeys. + * ShortcutRegistry.modifierKeys. * @return {string} The serialized key code for the given modifiers and key. * @public */ -Blockly.ShortcutRegistry.prototype.createSerializedKey = function( +ShortcutRegistry.prototype.createSerializedKey = function( keyCode, modifiers) { let serializedKey = ''; if (modifiers) { this.checkModifiers_(modifiers); - for (const modifier in Blockly.ShortcutRegistry.modifierKeys) { + for (const modifier in ShortcutRegistry.modifierKeys) { const modifierKeyCode = - Blockly.ShortcutRegistry.modifierKeys[modifier]; + ShortcutRegistry.modifierKeys[modifier]; if (modifiers.indexOf(modifierKeyCode) > -1) { if (serializedKey != '') { serializedKey += '+'; @@ -352,4 +353,6 @@ Blockly.ShortcutRegistry.prototype.createSerializedKey = function( }; // Creates and assigns the singleton instance. -new Blockly.ShortcutRegistry(); +new ShortcutRegistry(); + +exports = ShortcutRegistry; diff --git a/tests/deps.js b/tests/deps.js index de575339f..d67006c87 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -160,7 +160,7 @@ goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Ren goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', 'Blockly.Comment', 'Blockly.ContextMenuItems', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldLabelSerializable', 'Blockly.FieldMultilineInput', 'Blockly.FieldNumber', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.FlyoutButton', 'Blockly.Generator', 'Blockly.HorizontalFlyout', 'Blockly.Mutator', 'Blockly.ShortcutItems', 'Blockly.Themes.Classic', 'Blockly.Toolbox', 'Blockly.Trashcan', 'Blockly.VariablesDynamic', 'Blockly.VerticalFlyout', 'Blockly.Warning', 'Blockly.ZoomControls', 'Blockly.geras.Renderer', 'Blockly.thrasos.Renderer', 'Blockly.zelos.Renderer']); goog.addDependency('../../core/scrollbar.js', ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Events', 'Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Metrics', 'Blockly.utils.Svg', 'Blockly.utils.dom']); goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.utils.KeyCodes']); -goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object']); +goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils', 'Blockly.utils.object']); goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']); goog.addDependency('../../core/theme/zelos.js', ['Blockly.Themes.Zelos'], ['Blockly.Theme']); From 3519f4abc8d5352214a3a9f7851ca9ca9326afd1 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:28:19 -0700 Subject: [PATCH 3/4] Migrate core/shortcut_registry.js to named requires --- core/shortcut_registry.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index d75ec9546..ac492397a 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -14,10 +14,10 @@ goog.module('Blockly.ShortcutRegistry'); goog.module.declareLegacyNamespace(); -goog.require('Blockly.utils.KeyCodes'); -goog.require('Blockly.utils.object'); - -goog.requireType('Blockly.Workspace'); +const KeyCodes = goog.require('Blockly.utils.KeyCodes'); +/* eslint-disable-next-line no-unused-vars */ +const Workspace = goog.requireType('Blockly.Workspace'); +const object = goog.require('Blockly.utils.object'); /** @@ -47,22 +47,22 @@ const ShortcutRegistry = function() { /** * Enum of valid modifiers. - * @enum {!Blockly.utils.KeyCodes} + * @enum {!KeyCodes} */ ShortcutRegistry.modifierKeys = { - 'Shift': Blockly.utils.KeyCodes.SHIFT, - 'Control': Blockly.utils.KeyCodes.CTRL, - 'Alt': Blockly.utils.KeyCodes.ALT, - 'Meta': Blockly.utils.KeyCodes.META + 'Shift': KeyCodes.SHIFT, + 'Control': KeyCodes.CTRL, + 'Alt': KeyCodes.ALT, + 'Meta': KeyCodes.META }; /** * A keyboard shortcut. * @typedef {{ - * callback: ((function(!Blockly.Workspace, Event, + * callback: ((function(!Workspace, Event, * !ShortcutRegistry.KeyboardShortcut):boolean)|undefined), * name: string, - * preconditionFn: ((function(!Blockly.Workspace):boolean)|undefined), + * preconditionFn: ((function(!Workspace):boolean)|undefined), * metadata: (Object|undefined) * }} */ @@ -111,7 +111,7 @@ ShortcutRegistry.prototype.unregister = function(shortcutName) { /** * Adds a mapping between a keycode and a keyboard shortcut. - * @param {string|Blockly.utils.KeyCodes} keyCode The key code for the keyboard + * @param {string|KeyCodes} keyCode The key code for the keyboard * shortcut. If registering a key code with a modifier (ex: ctrl+c) use * ShortcutRegistry.registry.createSerializedKey; * @param {string} shortcutName The name of the shortcut to execute when the @@ -204,7 +204,7 @@ ShortcutRegistry.prototype.setKeyMap = function(keyMap) { * @public */ ShortcutRegistry.prototype.getKeyMap = function() { - return Blockly.utils.object.deepMerge(Object.create(null), this.keyMap_); + return object.deepMerge(Object.create(null), this.keyMap_); }; /** @@ -214,12 +214,12 @@ ShortcutRegistry.prototype.getKeyMap = function() { * @public */ ShortcutRegistry.prototype.getRegistry = function() { - return Blockly.utils.object.deepMerge(Object.create(null), this.registry_); + return object.deepMerge(Object.create(null), this.registry_); }; /** * Handles key down events. - * @param {!Blockly.Workspace} workspace The main workspace where the event was + * @param {!Workspace} workspace The main workspace where the event was * captured. * @param {!Event} e The key down event. * @return {boolean} True if the event was handled, false otherwise. @@ -308,7 +308,7 @@ ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { */ ShortcutRegistry.prototype.checkModifiers_ = function( modifiers) { - const validModifiers = Blockly.utils.object.values( + const validModifiers = object.values( ShortcutRegistry.modifierKeys); for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { From 9e2d6f2aba5b7c3d43a0705ce7d28f5b4d44cc76 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Mon, 26 Jul 2021 11:28:57 -0700 Subject: [PATCH 4/4] clang-format core/shortcut_registry.js --- core/shortcut_registry.js | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/core/shortcut_registry.js b/core/shortcut_registry.js index ac492397a..3da777eae 100644 --- a/core/shortcut_registry.js +++ b/core/shortcut_registry.js @@ -77,8 +77,7 @@ ShortcutRegistry.KeyboardShortcut; * @throws {Error} if a shortcut with the same name already exists. * @public */ -ShortcutRegistry.prototype.register = function( - shortcut, opt_allowOverrides) { +ShortcutRegistry.prototype.register = function(shortcut, opt_allowOverrides) { const registeredShortcut = this.registry_[shortcut.name]; if (registeredShortcut && !opt_allowOverrides) { throw new Error( @@ -168,7 +167,8 @@ ShortcutRegistry.prototype.removeKeyMapping = function( return true; } if (!opt_quiet) { - console.warn('No keyboard shortcut with name "' + shortcutName + + console.warn( + 'No keyboard shortcut with name "' + shortcutName + '" registered with key code "' + keyCode + '"'); } return false; @@ -176,9 +176,10 @@ ShortcutRegistry.prototype.removeKeyMapping = function( /** * Removes all the key mappings for a shortcut with the given name. - * Useful when changing the default key mappings and the key codes registered to the shortcut are - * unknown. - * @param {string} shortcutName The name of the shortcut to remove from the key map. + * Useful when changing the default key mappings and the key codes registered to + * the shortcut are unknown. + * @param {string} shortcutName The name of the shortcut to remove from the key + * map. * @public */ ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) { @@ -250,8 +251,7 @@ ShortcutRegistry.prototype.onKeyDown = function(workspace, e) { * given keyCode is used. Undefined if no shortcuts exist. * @public */ -ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( - keyCode) { +ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function(keyCode) { return this.keyMap_[keyCode] || []; }; @@ -263,8 +263,7 @@ ShortcutRegistry.prototype.getShortcutNamesByKeyCode = function( * registered under. * @public */ -ShortcutRegistry.prototype.getKeyCodesByShortcutName = function( - shortcutName) { +ShortcutRegistry.prototype.getKeyCodesByShortcutName = function(shortcutName) { const keys = []; for (const keyCode in this.keyMap_) { const shortcuts = this.keyMap_[keyCode]; @@ -306,10 +305,8 @@ ShortcutRegistry.prototype.serializeKeyEvent_ = function(e) { * @throws {Error} if the modifier is not in the valid modifiers list. * @private */ -ShortcutRegistry.prototype.checkModifiers_ = function( - modifiers) { - const validModifiers = object.values( - ShortcutRegistry.modifierKeys); +ShortcutRegistry.prototype.checkModifiers_ = function(modifiers) { + const validModifiers = object.values(ShortcutRegistry.modifierKeys); for (let i = 0, modifier; (modifier = modifiers[i]); i++) { if (validModifiers.indexOf(modifier) < 0) { throw new Error(modifier + ' is not a valid modifier key.'); @@ -326,15 +323,13 @@ ShortcutRegistry.prototype.checkModifiers_ = function( * @return {string} The serialized key code for the given modifiers and key. * @public */ -ShortcutRegistry.prototype.createSerializedKey = function( - keyCode, modifiers) { +ShortcutRegistry.prototype.createSerializedKey = function(keyCode, modifiers) { let serializedKey = ''; if (modifiers) { this.checkModifiers_(modifiers); for (const modifier in ShortcutRegistry.modifierKeys) { - const modifierKeyCode = - ShortcutRegistry.modifierKeys[modifier]; + const modifierKeyCode = ShortcutRegistry.modifierKeys[modifier]; if (modifiers.indexOf(modifierKeyCode) > -1) { if (serializedKey != '') { serializedKey += '+';