fix multiline text editor enter not working and begin edit on tiping

This commit is contained in:
Ezequiel Bergamaschi 2014-06-30 02:42:02 -03:00
parent 9afb13b02f
commit d4f72f3633
3 changed files with 17 additions and 49 deletions

View File

@ -21,7 +21,6 @@ mindplot.DesignerKeyboard = new Class({
Static:{ Static:{
register:function (designer) { register:function (designer) {
this._instance = new mindplot.DesignerKeyboard(designer); this._instance = new mindplot.DesignerKeyboard(designer);
//this._instance.activate();
}, },
getInstance:function () { getInstance:function () {
@ -256,53 +255,24 @@ mindplot.DesignerKeyboard = new Class({
} }
); );
var regex = /^(?:shift|control|ctrl|alt|meta)$/; $(document).on('keydown', function (event) {
var modifiers = ['shift', 'control', 'alt', 'meta'];
var excludes = ['esc', 'capslock', 'tab', 'f1', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12', 'backspace', 'down', 'up', 'left', 'right', 'control']; var keyCode = event.keyCode;
if (!Browser.Platform.mac) {
// This is to avoid enter on edition mode in the node when alt+tab is pressed.
excludes.push("alt");
}
/* if (!jQuery.hotkeys.specialKeys[keyCode] && !jQuery.hotkeys.shiftNums[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) {
var nodes = designer.getModel().filterSelectedTopics(); var nodes = designer.getModel().filterSelectedTopics();
if (nodes.length > 0) { if (nodes.length > 0) {
// If a modifier is press, the key selected must be ignored. // If a modifier is press, the key selected must be ignored.
var pressKey = event.key; var pressKey = String.fromCharCode(keyCode);
if (modifiers.contains(event.key)) { if (event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) {
pressKey = ""; pressKey = "";
} }
nodes[0].showTextEditor(pressKey); nodes[0].showTextEditor(pressKey);
event.stopPropagation(); event.stopPropagation();
} }
} }
}); });
*/
}, },

View File

@ -23,9 +23,7 @@ mindplot.Keyboard = new Class({
addShortcut: function(shortcuts, callback) { addShortcut: function(shortcuts, callback) {
if (!$.isArray(shortcuts)) { if (!$.isArray(shortcuts)) {
var value = shortcuts; shortcuts = [shortcuts];
shortcuts = [];
shortcuts.push(value);
} }
_.each(shortcuts, function(shortcut) { _.each(shortcuts, function(shortcut) {
$(document).bind('keydown', shortcut, callback); $(document).bind('keydown', shortcut, callback);

View File

@ -50,14 +50,14 @@ mindplot.MultilineTextEditor = new Class({
_registerEvents:function (containerElem) { _registerEvents:function (containerElem) {
var textareaElem = this._getTextareaElem(); var textareaElem = this._getTextareaElem();
var me = this;
textareaElem.on('keydown', function (event) { textareaElem.on('keydown', function (event) {
switch (event.key) { switch (jQuery.hotkeys.specialKeys[event.keyCode]) {
case 'esc': case 'esc':
this.close(false); me.close(false);
break; break;
case 'enter': case 'enter':
if (event.meta || event.control) { if (event.metaKey || event.ctrlKey) {
// Add return ... // Add return ...
var text = textareaElem.val(); var text = textareaElem.val();
@ -85,22 +85,22 @@ mindplot.MultilineTextEditor = new Class({
} }
else { else {
this.close(true); me.close(true);
} }
break; break;
} }
event.stopPropagation(); event.stopPropagation();
}.bind(this)); });
textareaElem.on('keypress', function (event) { textareaElem.on('keypress', function (event) {
event.stopPropagation(); event.stopPropagation();
}); });
textareaElem.on('keyup', function (event) { textareaElem.on('keyup', function (event) {
var text = this._getTextareaElem().val(); var text = me._getTextareaElem().val();
this.fireEvent('input', [event, text]); me.fireEvent('input', [event, text]);
this._adjustEditorSize(); me._adjustEditorSize();
}.bind(this)); });
// If the user clicks on the input, all event must be ignored ... // If the user clicks on the input, all event must be ignored ...
containerElem.on('click', function (event) { containerElem.on('click', function (event) {