From 6db9e31ab64330e6caf462ce927cff2a3fbe62be Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Tue, 11 Jan 2011 16:35:06 +0800 Subject: [PATCH] Use e.clipboardData.getData to get the pasted data if available. Increases speed if pasting a lot of lines --- lib/ace/textinput.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/ace/textinput.js b/lib/ace/textinput.js index 076f7875..5391c0e3 100644 --- a/lib/ace/textinput.js +++ b/lib/ace/textinput.js @@ -54,9 +54,9 @@ var TextInput = function(parentNode, host) { var inCompostion = false; var copied = false; - function sendText() { + function sendText(valueToSend) { if (!copied) { - var value = text.value; + var value = valueToSend || text.value; if (value) { if (value.charCodeAt(value.length-1) == PLACEHOLDER.charCodeAt(0)) { value = value.slice(0, -1); @@ -116,7 +116,19 @@ var TextInput = function(parentNode, host) { event.addListener(text, "keypress", onTextInput); event.addListener(text, "textInput", onTextInput); - event.addListener(text, "paste", onTextInput); + event.addListener(text, "paste", function(e) { + // Some browsers support the event.clipboardData API. Use this to get + // the pasted content which increases speed if pasting a lot of lines. + if (e.clipboardData && e.clipboardData.getData) { + sendText(e.clipboardData.getData("text/plain")); + e.preventDefault(); + } else + // If a browser doesn't support any of the things above, use the regular + // method to detect the pasted input. + { + onTextInput(); + } + }); event.addListener(text, "propertychange", onTextInput); event.addListener(text, "copy", onCopy);