From c9e3b65255577caf34ab1327c7e67a45799f686b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 25 Nov 2019 13:15:08 +0100 Subject: [PATCH] Avoinding rejection when shortcut keys are used and allowing 0 to 9 digits --- Canvas.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Canvas.js b/Canvas.js index fcc1c23b6..c548081b9 100644 --- a/Canvas.js +++ b/Canvas.js @@ -47,6 +47,7 @@ function newCanvas () { let splashScreen let lastContainerMouseOver + let lastShortcutKeyRejection return thisObject @@ -285,7 +286,7 @@ function newCanvas () { } if ((event.ctrlKey === true || event.metaKey === true) && event.altKey === true) { - if (event.keyCode >= 65 && event.keyCode <= 90) { + if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 65 && event.keyCode <= 90)) { /* From here we prevent the default behaviour */ event.preventDefault() @@ -304,8 +305,16 @@ function newCanvas () { nodeOnFocus.payload.uiObject.setValue('Shortcut Key Removed ') return } else { - nodeOnFocus.payload.uiObject.setErrorMessage('Key already in use by ' + nodeUsingThisKey.type + ' ' + nodeUsingThisKey.name) - return + if (lastShortcutKeyRejection !== event.key + nodeUsingThisKey.type + ' ' + nodeUsingThisKey.name) { + /* The first time we show a warning that this key is in use. */ + nodeOnFocus.payload.uiObject.setErrorMessage('Key already in use by ' + nodeUsingThisKey.type + ' ' + nodeUsingThisKey.name) + lastShortcutKeyRejection = event.key + nodeUsingThisKey.type + ' ' + nodeUsingThisKey.name + return + } else { + /* After the warning, we allow the key to be re-assigned */ + nodeUsingThisKey.payload.uiObject.shortcutKey = '' + nodeUsingThisKey === undefined + } } } /* If there is not node using this key and a node in focus, we assign this key to this node */