Minor fix to position cursor.

This commit is contained in:
Paulo Veiga 2011-09-05 09:25:38 -03:00
parent 0e21aad802
commit 12221ab0af
2 changed files with 25 additions and 21 deletions

View File

@ -43,7 +43,7 @@ mindplot.MultilineTextEditor = new Class({
textareaElem.setStyles({ textareaElem.setStyles({
border: "1px gray dashed", border: "1px gray dashed",
background:"transparent", background:"rgba(98, 135, 167, .3)",
outline: '0 none', outline: '0 none',
resize: 'none', resize: 'none',
overflow:"hidden" overflow:"hidden"
@ -181,8 +181,7 @@ mindplot.MultilineTextEditor = new Class({
// Set the element focus and select the current text ... // Set the element focus and select the current text ...
var inputElem = this._getTextareaElem(); var inputElem = this._getTextareaElem();
inputElem.focus(); this._positionCursor(inputElem, !$defined(defaultText));
this._changeCursor(inputElem, $defined(defaultText));
}.bind(this); }.bind(this);
@ -228,24 +227,29 @@ mindplot.MultilineTextEditor = new Class({
return this._containerElem.getElement('textarea'); return this._containerElem.getElement('textarea');
}, },
_changeCursor : function(textareaElem, selectText) { _positionCursor : function(textareaElem, selectText) {
// Select text if it's required ... textareaElem.focus();
if (textareaElem.createTextRange) //ie if (selectText) {
{ // Mark text as selected ...
var range = textareaElem.createTextRange(); if (textareaElem.createTextRange) {
var pos = textareaElem.value.length; var rang = textareaElem.createTextRange();
if (!selectText) { rang.select();
range.select(); rang.move("character", textareaElem.value.length);
range.move("character", pos);
} }
else { else {
range.move("character", pos);
range.select();
}
}
else if (!selectText) {
textareaElem.setSelectionRange(0, textareaElem.value.length); textareaElem.setSelectionRange(0, textareaElem.value.length);
} }
} else {
// Move the cursor to the last character ..
if (textareaElem.createTextRange) {
var range = textareaElem.createTextRange();
range.move("character", textareaElem.value.length);
} else {
textareaElem.selectionStart = textareaElem.value.length;
}
}
}, },
close : function(update) { close : function(update) {

View File

@ -161,9 +161,9 @@ mindplot.TextEditor = new Class({
var elemSize = topic.getSize(); var elemSize = topic.getSize();
this._setEditorSize(elemSize.width, elemSize.height); this._setEditorSize(elemSize.width, elemSize.height);
var inputElem = this._getTextareaElem(); var textareaElem = this._getTextareaElem();
inputElem.focus(); textareaElem.focus();
this._changeCursor(inputElem, $defined(defaultText)); this._positionCursor(textareaElem, !$defined(defaultText));
}.bind(this); }.bind(this);
@ -225,7 +225,7 @@ mindplot.TextEditor = new Class({
this._containerElem.style.height = this._size.height + "px"; this._containerElem.style.height = this._size.height + "px";
}, },
_changeCursor : function(inputElem, selectText) { _positionCursor : function(inputElem, selectText) {
// Select text if it's required ... // Select text if it's required ...
if (inputElem.createTextRange) //ie if (inputElem.createTextRange) //ie
{ {