Ensure user keyboard shortcuts override defaults

Fixes #2753
This commit is contained in:
Nick O'Leary 2020-11-09 21:13:20 +00:00
parent f878ffc01b
commit ebe604e1af
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 35 additions and 4 deletions

View File

@ -21,7 +21,18 @@ RED.actions = (function() {
var result = [];
Object.keys(actions).forEach(function(action) {
var shortcut = RED.keyboard.getShortcut(action);
result.push({id:action,scope:shortcut?shortcut.scope:undefined,key:shortcut?shortcut.key:undefined,user:shortcut?shortcut.user:undefined})
var isUser = false;
if (shortcut) {
isUser = shortcut.user;
} else {
isUser = !!RED.keyboard.getUserShortcut(action);
}
result.push({
id:action,
scope:shortcut?shortcut.scope:undefined,
key:shortcut?shortcut.key:undefined,
user:isUser
})
})
return result;
}

View File

@ -70,6 +70,11 @@ RED.keyboard = (function() {
}
}
}
function getUserKey(action) {
var currentEditorSettings = RED.settings.get('editor') || {};
var userKeymap = currentEditorSettings.keymap || {};
return userKeymap[action];
}
function init() {
// Migrate from pre-0.18
migrateOldKeymap();
@ -255,6 +260,19 @@ RED.keyboard = (function() {
var i=0;
if (typeof key === 'string') {
if (typeof cbdown === 'string') {
if (!ondown && !defaultKeyMap.hasOwnProperty(cbdown)) {
defaultKeyMap[cbdown] = {
scope:scope,
key:key,
user:false
}
}
if (!ondown) {
var userAction = getUserKey(cbdown);
if (userAction) {
return;
}
}
actionToKeyMap[cbdown] = {scope:scope,key:key};
if (typeof ondown === 'boolean') {
actionToKeyMap[cbdown].user = ondown;
@ -417,11 +435,9 @@ RED.keyboard = (function() {
});
revertButton.on("click", function(e) {
e.stopPropagation();
RED.keyboard.revertToDefault(object.id);
container.empty();
container.removeClass('keyboard-shortcut-entry-expanded');
var shortcut = RED.keyboard.getShortcut(object.id);
var userKeymap = RED.settings.get('keymap') || {};
// var userKeymap = RED.settings.get('keymap') || {};
var currentEditorSettings = RED.settings.get('editor') || {};
var userKeymap = currentEditorSettings.keymap || {};
@ -429,6 +445,9 @@ RED.keyboard = (function() {
currentEditorSettings.keymap = userKeymap;
RED.settings.set('editor',currentEditorSettings);
RED.keyboard.revertToDefault(object.id);
var shortcut = RED.keyboard.getShortcut(object.id);
var obj = {
id:object.id,
scope:shortcut?shortcut.scope:undefined,
@ -589,6 +608,7 @@ RED.keyboard = (function() {
getShortcut: function(actionName) {
return actionToKeyMap[actionName];
},
getUserShortcut: getUserKey,
revertToDefault: revertToDefault,
formatKey: formatKey,
validateKey: validateKey,