Add a remove all key mapping function (#4498)

This commit is contained in:
alschmiedt
2020-12-09 16:50:10 -08:00
committed by GitHub
parent 29b96d8d35
commit 45478bdbe9

View File

@@ -104,10 +104,7 @@ Blockly.ShortcutRegistry.prototype.unregister = function(shortcutName) {
return false;
}
// Remove all key mappings with this shortcut.
for (var keyCode in this.keyMap_) {
this.removeKeyMapping(keyCode, shortcutName, true);
}
this.removeAllKeyMappings(shortcutName);
delete this.registry_[shortcutName];
return true;
@@ -178,6 +175,19 @@ Blockly.ShortcutRegistry.prototype.removeKeyMapping = function(
return false;
};
/**
* 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.
* @public
*/
Blockly.ShortcutRegistry.prototype.removeAllKeyMappings = function(shortcutName) {
for (var keyCode in this.keyMap_) {
this.removeKeyMapping(keyCode, shortcutName, true);
}
};
/**
* Sets the key map. Setting the key map will override any default key mappings.
* @param {!Object<string, !Array<string>>} keyMap The object with key code to