Enter is supported in any part of the text node. Not only at the end.

main
Paulo Gustavo Veiga 2012-09-13 01:22:20 -03:00
parent 011acba666
commit bef8711138
1 changed files with 61 additions and 39 deletions

View File

@ -63,8 +63,30 @@ mindplot.MultilineTextEditor = new Class({
case 'enter':
if (event.meta || event.control) {
// @todo: Enters must be in any place ...
textareaElem.value = textareaElem.value + "\n";
// Add return ...
var text = textareaElem.value;
var cursorPosition = text.length;
if (textareaElem.selectionStart) {
cursorPosition = textareaElem.selectionStart;
}
var head = text.substring(0, cursorPosition);
var tail = "";
if (cursorPosition < text.length) {
tail = text.substring(cursorPosition, text.length);
}
textareaElem.value = head + "\n" + tail;
// Position cursor ...
if (textareaElem.setSelectionRange) {
textareaElem.focus();
textareaElem.setSelectionRange(cursorPosition + 1, cursorPosition + 1);
} else if (textareaElem.createTextRange) {
var range = textareaElem.createTextRange();
range.moveStart('character', cursorPosition + 1);
range.select();
}
}
else {
this.close(true);