From 39532a9d6507fc9b40fe0413fc2208accf862bcc Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sat, 27 Feb 2021 21:58:22 +0000 Subject: [PATCH] Fix keymap entries with multiple keys for same action --- .../editor-client/src/js/ui/keyboard.js | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/keyboard.js b/packages/node_modules/@node-red/editor-client/src/js/ui/keyboard.js index 5a17d14b0..0d1c72231 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/keyboard.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/keyboard.js @@ -76,20 +76,29 @@ RED.keyboard = (function() { } function mergeKeymaps(defaultKeymap, themeKeymap) { - // defaultKeymap has format: { scope: { action: key , action: key }} + // defaultKeymap has format: { scope: { key: action , key: action }} // themeKeymap has format: {action: {scope,key}, action: {scope:key}} + var mergedKeymap = {}; for (var scope in defaultKeymap) { if (defaultKeymap.hasOwnProperty(scope)) { var keys = defaultKeymap[scope]; for (var key in keys) { if (keys.hasOwnProperty(key)) { - mergedKeymap[keys[key]] = { - scope:scope, - key:key, - user:false - }; + if (!mergedKeymap[keys[key]]) { + mergedKeymap[keys[key]] = [{ + scope:scope, + key:key, + user:false + }]; + } else { + mergedKeymap[keys[key]].push({ + scope:scope, + key:key, + user:false + }) + } } } } @@ -100,13 +109,13 @@ RED.keyboard = (function() { // No key for this action - default is no keybinding delete mergedKeymap[action] } else { - mergedKeymap[action] = { + mergedKeymap[action] = [{ scope: themeKeymap[action].scope || "*", - key: themeKeymap[action].key, + key: [themeKeymap[action].key], user: false - } - if (mergedKeymap[action].scope === "workspace") { - mergedKeymap[action].scope = "red-ui-workspace"; + }] + if (mergedKeymap[action][0].scope === "workspace") { + mergedKeymap[action][0].scope = "red-ui-workspace"; } } } @@ -121,15 +130,17 @@ RED.keyboard = (function() { var userKeymap = RED.settings.get('editor.keymap', {}); $.getJSON("red/keymap.json",function(defaultKeymap) { var keymap = mergeKeymaps(defaultKeymap, RED.settings.theme('keymap',{})); - // keymap has the format: {action: {scope,key}, action: {scope:key}} + // keymap has the format: {action: [{scope,key},{scope,key}], action: [{scope:key}]} var action; for (action in keymap) { if (keymap.hasOwnProperty(action)) { if (!userKeymap.hasOwnProperty(action)) { - addHandler(keymap[action].scope,keymap[action].key,action,false); + keymap[action].forEach(function(km) { + addHandler(km.scope,km.key,action,false); + }); } - defaultKeyMap[action] = keymap[action]; + defaultKeyMap[action] = keymap[action][0]; } }