mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 14:17:57 +01:00
fix multiline text editor enter not working and begin edit on tiping
This commit is contained in:
parent
9afb13b02f
commit
d4f72f3633
@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
},
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user