fix copy after typing

This commit is contained in:
nightwing 2012-11-30 20:26:04 +04:00
commit 378e5f35e9

View file

@ -78,17 +78,25 @@ var TextInput = function(parentNode, host) {
var tempStyle = '';
function resetValue() {
if (inCompostion)
return;
text.value = PLACEHOLDER;
//http://code.google.com/p/chromium/issues/detail?id=76516
if (useragent.isWebKit && !resetTimeout)
if (!resetTimeout) {
resetTimeout = setTimeout(function(){
text.value = PLACEHOLDER;
resetSelection();
resetTimeout = null;
if (inCompostion)
return;
if (useragent.isWebKit)
text.value = PLACEHOLDER;
resetSelection();
});
}
};
function resetSelection(isEmpty) {
if (inCompostion)
return;
var selectionStart = isEmpty ? 2 : 1;
var selectionEnd = 2;
// on firefox this throws if textarea is hidden
@ -125,32 +133,30 @@ var TextInput = function(parentNode, host) {
var onInput = function(e) {
if (inCompostion)
return;
var data = text.value;
resetValue();
if (pasted) {
var data = text.value;
resetValue();
resetSelection();
if (data)
host.onPaste(data);
pasted = false;
return;
}
var data = text.value;
if (data.substring(0, 2) == PLACEHOLDER)
data = data.substr(2);
else
data = data.substr(1);
resetValue();
if (data) {
// can happen if undo in textarea isn't stopped
if (data[data.length - 1] == PLACEHOLDER[0])
data = data.slice(0, -1);
if (data)
host.onTextInput(data);
} else
} else if (data == PLACEHOLDER[0]) {
host.execCommand("del", {source: "ace"});
} else {
if (data.substring(0, 2) == PLACEHOLDER)
data = data.substr(2);
else if (data[0] == PLACEHOLDER[0])
data = data.substr(1);
if (data) {
// can happen if undo in textarea isn't stopped
if (data[data.length - 1] == PLACEHOLDER[0])
data = data.slice(0, -1);
if (data)
host.onTextInput(data);
}
}
};
var onCompositionStart = function(e) {