From d4f72f363366bc8be48195cefc5e61ed70481949 Mon Sep 17 00:00:00 2001 From: Ezequiel Bergamaschi Date: Mon, 30 Jun 2014 02:42:02 -0300 Subject: [PATCH] fix multiline text editor enter not working and begin edit on tiping --- .../src/main/javascript/DesignerKeyboard.js | 40 +++---------------- mindplot/src/main/javascript/Keyboard.js | 4 +- .../main/javascript/MultilineTextEditor.js | 22 +++++----- 3 files changed, 17 insertions(+), 49 deletions(-) diff --git a/mindplot/src/main/javascript/DesignerKeyboard.js b/mindplot/src/main/javascript/DesignerKeyboard.js index 762cdb91..2865a38c 100644 --- a/mindplot/src/main/javascript/DesignerKeyboard.js +++ b/mindplot/src/main/javascript/DesignerKeyboard.js @@ -21,7 +21,6 @@ mindplot.DesignerKeyboard = new Class({ Static:{ register:function (designer) { this._instance = new mindplot.DesignerKeyboard(designer); - //this._instance.activate(); }, getInstance:function () { @@ -256,53 +255,24 @@ mindplot.DesignerKeyboard = new Class({ } ); - var regex = /^(?:shift|control|ctrl|alt|meta)$/; - var modifiers = ['shift', 'control', 'alt', 'meta']; + $(document).on('keydown', function (event) { - var excludes = ['esc', 'capslock', 'tab', 'f1', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12', 'backspace', 'down', 'up', 'left', 'right', 'control']; - if (!Browser.Platform.mac) { - // This is to avoid enter on edition mode in the node when alt+tab is pressed. - excludes.push("alt"); - } + var keyCode = event.keyCode; -/* - document.id(document).addEvent('keydown', function (event) { - - // Convert key to mootools keyboard event format... - var keys = []; - modifiers.each(function (mod) { - if (event[mod]) keys.push(mod); - }); - if (!regex.test(event.key)) - keys.push(event.key); - var key = keys.join('+'); - - // Is the pressed key one of the already registered in the keyboard ? - var isRegistered = false; - for (var eKey in keyboardEvents) { - if (eKey == key) { - isRegistered = true; - break; - } - } - - // If it's not registered, let's - if (!isRegistered && !excludes.contains(key) && !excludes.contains(event.key) && !event.meta && !event.control) { + if (!jQuery.hotkeys.specialKeys[keyCode] && !jQuery.hotkeys.shiftNums[keyCode]) { var nodes = designer.getModel().filterSelectedTopics(); if (nodes.length > 0) { // If a modifier is press, the key selected must be ignored. - var pressKey = event.key; - if (modifiers.contains(event.key)) { + var pressKey = String.fromCharCode(keyCode); + if (event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) { pressKey = ""; } - nodes[0].showTextEditor(pressKey); event.stopPropagation(); } } }); -*/ }, diff --git a/mindplot/src/main/javascript/Keyboard.js b/mindplot/src/main/javascript/Keyboard.js index 4ca20edd..fc74ceb6 100644 --- a/mindplot/src/main/javascript/Keyboard.js +++ b/mindplot/src/main/javascript/Keyboard.js @@ -23,9 +23,7 @@ mindplot.Keyboard = new Class({ addShortcut: function(shortcuts, callback) { if (!$.isArray(shortcuts)) { - var value = shortcuts; - shortcuts = []; - shortcuts.push(value); + shortcuts = [shortcuts]; } _.each(shortcuts, function(shortcut) { $(document).bind('keydown', shortcut, callback); diff --git a/mindplot/src/main/javascript/MultilineTextEditor.js b/mindplot/src/main/javascript/MultilineTextEditor.js index 4e5133b7..c36efdac 100644 --- a/mindplot/src/main/javascript/MultilineTextEditor.js +++ b/mindplot/src/main/javascript/MultilineTextEditor.js @@ -50,14 +50,14 @@ mindplot.MultilineTextEditor = new Class({ _registerEvents:function (containerElem) { var textareaElem = this._getTextareaElem(); - + var me = this; textareaElem.on('keydown', function (event) { - switch (event.key) { + switch (jQuery.hotkeys.specialKeys[event.keyCode]) { case 'esc': - this.close(false); + me.close(false); break; case 'enter': - if (event.meta || event.control) { + if (event.metaKey || event.ctrlKey) { // Add return ... var text = textareaElem.val(); @@ -85,22 +85,22 @@ mindplot.MultilineTextEditor = new Class({ } else { - this.close(true); + me.close(true); } break; } event.stopPropagation(); - }.bind(this)); + }); textareaElem.on('keypress', function (event) { event.stopPropagation(); }); textareaElem.on('keyup', function (event) { - var text = this._getTextareaElem().val(); - this.fireEvent('input', [event, text]); - this._adjustEditorSize(); - }.bind(this)); + var text = me._getTextareaElem().val(); + me.fireEvent('input', [event, text]); + me._adjustEditorSize(); + }); // If the user clicks on the input, all event must be ignored ... containerElem.on('click', function (event) { @@ -151,7 +151,7 @@ mindplot.MultilineTextEditor = new Class({ } }, - show:function (topic, text) { + show: function (topic, text) { // Close a previous node editor if it's opened ... if (this._topic) { this.close(false);