fix editor loosing focus on input
This commit is contained in:
parent
67a4a3329c
commit
3c57b1b415
1 changed files with 22 additions and 25 deletions
|
|
@ -73,35 +73,38 @@ var TextInput = function(parentNode, host) {
|
||||||
|
|
||||||
var inCompostion = false;
|
var inCompostion = false;
|
||||||
|
|
||||||
var isSelectionEmpty = true;
|
var resetTimeout = true;
|
||||||
|
|
||||||
var tempStyle = '';
|
var tempStyle = '';
|
||||||
|
|
||||||
function resetValue() {
|
function resetValue() {
|
||||||
text.value = PLACEHOLDER;
|
text.value = PLACEHOLDER;
|
||||||
//http://code.google.com/p/chromium/issues/detail?id=76516
|
//http://code.google.com/p/chromium/issues/detail?id=76516
|
||||||
if (useragent.isWebKit)
|
if (useragent.isWebKit && !resetTimeout)
|
||||||
setTimeout(function(){
|
resetTimeout = setTimeout(function(){
|
||||||
text.value = PLACEHOLDER;
|
text.value = PLACEHOLDER;
|
||||||
resetSelection();
|
resetSelection();
|
||||||
|
resetTimeout = null;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function resetSelection() {
|
function resetSelection(isEmpty) {
|
||||||
var selectionStart = isSelectionEmpty ? 2 : 1;
|
var selectionStart = isEmpty ? 2 : 1;
|
||||||
var selectionEnd = 2;
|
var selectionEnd = 2;
|
||||||
|
// on firefox this throws if textarea is hidden
|
||||||
if (text.setSelectionRange) {
|
try {
|
||||||
text.setSelectionRange(selectionStart, selectionEnd);
|
if (text.setSelectionRange) {
|
||||||
}
|
text.setSelectionRange(selectionStart, selectionEnd);
|
||||||
// IE8 does not support setSelectionRange
|
}
|
||||||
else if (text.createTextRange) {
|
// IE8 does not support setSelectionRange
|
||||||
var range = text.createTextRange();
|
else if (text.createTextRange) {
|
||||||
range.collapse(true);
|
var range = text.createTextRange();
|
||||||
range.moveEnd('character', selectionEnd);
|
range.collapse(true);
|
||||||
range.moveStart('character', selectionStart);
|
range.moveEnd('character', selectionEnd);
|
||||||
range.select();
|
range.moveStart('character', selectionStart);
|
||||||
}
|
range.select();
|
||||||
|
}
|
||||||
|
} catch(e){}
|
||||||
};
|
};
|
||||||
|
|
||||||
var onSelect = function(e) {
|
var onSelect = function(e) {
|
||||||
|
|
@ -326,6 +329,8 @@ var TextInput = function(parentNode, host) {
|
||||||
(useragent.isIE ? "background:rgba(0, 0, 0, 0.03); opacity:0.1;" : "") + //"background:rgba(250, 0, 0, 0.3); opacity:1;" +
|
(useragent.isIE ? "background:rgba(0, 0, 0, 0.03); opacity:0.1;" : "") + //"background:rgba(250, 0, 0, 0.3); opacity:1;" +
|
||||||
"left:" + (e.clientX - 2) + "px; top:" + (e.clientY - 2) + "px;";
|
"left:" + (e.clientX - 2) + "px; top:" + (e.clientY - 2) + "px;";
|
||||||
|
|
||||||
|
resetSelection(host.selection.isEmpty());
|
||||||
|
|
||||||
if (e.type != "mousedown")
|
if (e.type != "mousedown")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -360,14 +365,6 @@ var TextInput = function(parentNode, host) {
|
||||||
host.textInput.onContextMenu(e);
|
host.textInput.onContextMenu(e);
|
||||||
onContextMenuClose();
|
onContextMenuClose();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
host.addEventListener('changeSelection', function(){
|
|
||||||
if (host.selection.isEmpty() != isSelectionEmpty) {
|
|
||||||
isSelectionEmpty = !isSelectionEmpty;
|
|
||||||
resetSelection();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.TextInput = TextInput;
|
exports.TextInput = TextInput;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue