mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Prevent duplicate keyboard shortcut from being assigned
This commit is contained in:
parent
f69d6b4eb1
commit
8e65408b1c
@ -20,6 +20,9 @@ RED.keyboard = (function() {
|
|||||||
var handlersActive = true;
|
var handlersActive = true;
|
||||||
|
|
||||||
var handlers = {};
|
var handlers = {};
|
||||||
|
|
||||||
|
var knownShortcuts;
|
||||||
|
|
||||||
var partialState;
|
var partialState;
|
||||||
|
|
||||||
var keyMap = {
|
var keyMap = {
|
||||||
@ -453,14 +456,21 @@ RED.keyboard = (function() {
|
|||||||
container.addClass('keyboard-shortcut-entry-expanded');
|
container.addClass('keyboard-shortcut-entry-expanded');
|
||||||
|
|
||||||
var keyInput = $('<input type="text">').attr('placeholder',RED._('keyboard.unassigned')).val(object.key||"").appendTo(key);
|
var keyInput = $('<input type="text">').attr('placeholder',RED._('keyboard.unassigned')).val(object.key||"").appendTo(key);
|
||||||
keyInput.on("keyup",function(e) {
|
keyInput.on("change paste keyup",function(e) {
|
||||||
if (e.keyCode === 13) {
|
if (e.keyCode === 13 && !$(this).hasClass("input-error")) {
|
||||||
return endEditShortcut();
|
return endEditShortcut();
|
||||||
}
|
}
|
||||||
|
if (e.keyCode === 27) {
|
||||||
|
return endEditShortcut(true);
|
||||||
|
}
|
||||||
var currentVal = $(this).val();
|
var currentVal = $(this).val();
|
||||||
currentVal = currentVal.trim();
|
currentVal = currentVal.trim();
|
||||||
var valid = (currentVal === "" || RED.keyboard.validateKey(currentVal));
|
var valid = (currentVal === "" || RED.keyboard.validateKey(currentVal));
|
||||||
|
if (valid && currentVal !== "") {
|
||||||
|
valid = !knownShortcuts.has(scopeSelect.val()+":"+currentVal.toLowerCase());
|
||||||
|
}
|
||||||
$(this).toggleClass("input-error",!valid);
|
$(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);
|
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";
|
object.scope = "red-ui-workspace";
|
||||||
}
|
}
|
||||||
scopeSelect.val(object.scope||'*');
|
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 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);
|
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();
|
keyDiv.empty();
|
||||||
scopeDiv.empty();
|
scopeDiv.empty();
|
||||||
if (object.key) {
|
if (object.key) {
|
||||||
|
knownShortcuts.delete(object.scope+":"+object.key);
|
||||||
RED.keyboard.remove(object.key,true);
|
RED.keyboard.remove(object.key,true);
|
||||||
}
|
}
|
||||||
container.find(".keyboard-shortcut-entry-text i").css("opacity",1);
|
container.find(".keyboard-shortcut-entry-text i").css("opacity",1);
|
||||||
@ -535,10 +549,10 @@ RED.keyboard = (function() {
|
|||||||
$("<span>").text(scope).appendTo(scopeDiv);
|
$("<span>").text(scope).appendTo(scopeDiv);
|
||||||
object.key = key;
|
object.key = key;
|
||||||
object.scope = scope;
|
object.scope = scope;
|
||||||
|
knownShortcuts.add(object.scope+":"+object.key);
|
||||||
RED.keyboard.add(object.scope,object.key,object.id,true);
|
RED.keyboard.add(object.scope,object.key,object.id,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var userKeymap = RED.settings.get('editor.keymap', {});
|
var userKeymap = RED.settings.get('editor.keymap', {});
|
||||||
var shortcut = RED.keyboard.getShortcut(object.id);
|
var shortcut = RED.keyboard.getShortcut(object.id);
|
||||||
userKeymap[object.id] = {
|
userKeymap[object.id] = {
|
||||||
@ -633,7 +647,11 @@ RED.keyboard = (function() {
|
|||||||
var Bid = B.id.replace(/^.*:/,"").replace(/[ -]/g,"").toLowerCase();
|
var Bid = B.id.replace(/^.*:/,"").replace(/[ -]/g,"").toLowerCase();
|
||||||
return Aid.localeCompare(Bid);
|
return Aid.localeCompare(Bid);
|
||||||
});
|
});
|
||||||
|
knownShortcuts = new Set();
|
||||||
shortcuts.forEach(function(s) {
|
shortcuts.forEach(function(s) {
|
||||||
|
if (s.key) {
|
||||||
|
knownShortcuts.add(s.scope+":"+s.key);
|
||||||
|
}
|
||||||
shortcutList.editableList('addItem',s);
|
shortcutList.editableList('addItem',s);
|
||||||
});
|
});
|
||||||
return pane;
|
return pane;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user