From 2f01870f0574bc38aa11b1a1deae2739f9b4c489 Mon Sep 17 00:00:00 2001 From: DanyaPostfactum Date: Fri, 30 Nov 2012 20:11:09 +1000 Subject: [PATCH 1/4] Fix old way paste (reset a selection) --- lib/ace/keyboard/textinput.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index dfad806b..32e179ac 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -129,6 +129,7 @@ var TextInput = function(parentNode, host) { if (pasted) { var data = text.value; resetValue(); + resetSelection(); if (data) host.onPaste(data); pasted = false; From 81f58c4552984c08f79c55e61cd8ce4da1e64b82 Mon Sep 17 00:00:00 2001 From: DanyaPostfactum Date: Fri, 30 Nov 2012 20:18:44 +1000 Subject: [PATCH 2/4] Restore textarea selection after paste in IE --- lib/ace/keyboard/textinput.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index 32e179ac..ca41130e 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -239,6 +239,8 @@ var TextInput = function(parentNode, host) { var data = clipboardData.getData("Text"); if (data) host.onPaste(data); + if (useragent.isIE) + setTimeout(resetSelection); event.preventDefault(e); } else { From 8571bee03759eca30754cbc90d80d2e0751ee650 Mon Sep 17 00:00:00 2001 From: DanyaPostfactum Date: Fri, 30 Nov 2012 20:32:50 +1000 Subject: [PATCH 3/4] Replace nonexistent method onDelete call with execCommand("del") in textinput --- lib/ace/keyboard/textinput.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index ca41130e..7b528197 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -150,7 +150,7 @@ var TextInput = function(parentNode, host) { if (data) host.onTextInput(data); } else - host.onDelete(); + host.execCommand("del", {source: "ace"}); }; var onCompositionStart = function(e) { From 378e5f35e9c3250e4844160864240a249a8e749a Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 30 Nov 2012 20:26:04 +0400 Subject: [PATCH 4/4] fix copy after typing --- lib/ace/keyboard/textinput.js | 50 ++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index 7b528197..4e07d24a 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -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) {