Merge pull request #1132 from danyaPostfactum/copypastefixes
Copy/paste/delete fixes
This commit is contained in:
commit
7b65e64ffa
1 changed files with 31 additions and 22 deletions
|
|
@ -78,17 +78,25 @@ var TextInput = function(parentNode, host) {
|
||||||
var tempStyle = '';
|
var tempStyle = '';
|
||||||
|
|
||||||
function resetValue() {
|
function resetValue() {
|
||||||
|
if (inCompostion)
|
||||||
|
return;
|
||||||
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 && !resetTimeout)
|
if (!resetTimeout) {
|
||||||
resetTimeout = setTimeout(function(){
|
resetTimeout = setTimeout(function(){
|
||||||
text.value = PLACEHOLDER;
|
|
||||||
resetSelection();
|
|
||||||
resetTimeout = null;
|
resetTimeout = null;
|
||||||
|
if (inCompostion)
|
||||||
|
return;
|
||||||
|
if (useragent.isWebKit)
|
||||||
|
text.value = PLACEHOLDER;
|
||||||
|
resetSelection();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function resetSelection(isEmpty) {
|
function resetSelection(isEmpty) {
|
||||||
|
if (inCompostion)
|
||||||
|
return;
|
||||||
var selectionStart = isEmpty ? 2 : 1;
|
var selectionStart = isEmpty ? 2 : 1;
|
||||||
var selectionEnd = 2;
|
var selectionEnd = 2;
|
||||||
// on firefox this throws if textarea is hidden
|
// on firefox this throws if textarea is hidden
|
||||||
|
|
@ -125,31 +133,30 @@ var TextInput = function(parentNode, host) {
|
||||||
var onInput = function(e) {
|
var onInput = function(e) {
|
||||||
if (inCompostion)
|
if (inCompostion)
|
||||||
return;
|
return;
|
||||||
|
var data = text.value;
|
||||||
|
resetValue();
|
||||||
|
|
||||||
if (pasted) {
|
if (pasted) {
|
||||||
var data = text.value;
|
resetSelection();
|
||||||
resetValue();
|
|
||||||
if (data)
|
if (data)
|
||||||
host.onPaste(data);
|
host.onPaste(data);
|
||||||
pasted = false;
|
pasted = false;
|
||||||
return;
|
} 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 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
|
|
||||||
host.onDelete();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var onCompositionStart = function(e) {
|
var onCompositionStart = function(e) {
|
||||||
|
|
@ -238,6 +245,8 @@ var TextInput = function(parentNode, host) {
|
||||||
var data = clipboardData.getData("Text");
|
var data = clipboardData.getData("Text");
|
||||||
if (data)
|
if (data)
|
||||||
host.onPaste(data);
|
host.onPaste(data);
|
||||||
|
if (useragent.isIE)
|
||||||
|
setTimeout(resetSelection);
|
||||||
event.preventDefault(e);
|
event.preventDefault(e);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue