1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Prevent duplicate keyboard shortcut from being assigned

This commit is contained in:
Nick O'Leary 2021-03-01 20:50:08 +00:00
parent f69d6b4eb1
commit 8e65408b1c
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -20,6 +20,9 @@ RED.keyboard = (function() {
var handlersActive = true;
var handlers = {};
var knownShortcuts;
var partialState;
var keyMap = {
@ -453,14 +456,21 @@ RED.keyboard = (function() {
container.addClass('keyboard-shortcut-entry-expanded');
var keyInput = $('<input type="text">').attr('placeholder',RED._('keyboard.unassigned')).val(object.key||"").appendTo(key);
keyInput.on("keyup",function(e) {
if (e.keyCode === 13) {
keyInput.on("change paste keyup",function(e) {
if (e.keyCode === 13 && !$(this).hasClass("input-error")) {
return endEditShortcut();
}
if (e.keyCode === 27) {
return endEditShortcut(true);
}
var currentVal = $(this).val();
currentVal = currentVal.trim();
var valid = (currentVal === "" || RED.keyboard.validateKey(currentVal));
if (valid && currentVal !== "") {
valid = !knownShortcuts.has(scopeSelect.val()+":"+currentVal.toLowerCase());
}
$(this).toggleClass("input-error",!valid);
okButton.attr("disabled",!valid);
})
var scopeSelect = $('<select><option value="*" data-i18n="keyboard.global"></option><option value="red-ui-workspace" data-i18n="keyboard.workspace"></option></select>').appendTo(scope);
@ -469,6 +479,9 @@ RED.keyboard = (function() {
object.scope = "red-ui-workspace";
}
scopeSelect.val(object.scope||'*');
scopeSelect.on("change", function() {
keyInput.trigger("change");
})
var div = $('<div class="keyboard-shortcut-edit button-group-vertical"></div>').appendTo(scope);
var okButton = $('<button class="red-ui-button red-ui-button-small"><i class="fa fa-check"></i></button>').appendTo(div);
@ -521,6 +534,7 @@ RED.keyboard = (function() {
keyDiv.empty();
scopeDiv.empty();
if (object.key) {
knownShortcuts.delete(object.scope+":"+object.key);
RED.keyboard.remove(object.key,true);
}
container.find(".keyboard-shortcut-entry-text i").css("opacity",1);
@ -535,10 +549,10 @@ RED.keyboard = (function() {
$("<span>").text(scope).appendTo(scopeDiv);
object.key = key;
object.scope = scope;
knownShortcuts.add(object.scope+":"+object.key);
RED.keyboard.add(object.scope,object.key,object.id,true);
}
var userKeymap = RED.settings.get('editor.keymap', {});
var shortcut = RED.keyboard.getShortcut(object.id);
userKeymap[object.id] = {
@ -633,7 +647,11 @@ RED.keyboard = (function() {
var Bid = B.id.replace(/^.*:/,"").replace(/[ -]/g,"").toLowerCase();
return Aid.localeCompare(Bid);
});
knownShortcuts = new Set();
shortcuts.forEach(function(s) {
if (s.key) {
knownShortcuts.add(s.scope+":"+s.key);
}
shortcutList.editableList('addItem',s);
});
return pane;