From 03816b05c756f026d178043ab5c2d3b8b4a982c4 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Wed, 18 Apr 2012 19:18:50 -0700 Subject: [PATCH] Modify where keyboard cut/copy can come from --- lib/ace/keyboard/textinput.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index bb917f5b..aa724796 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -129,9 +129,12 @@ var TextInput = function(parentNode, host) { var onCopy = function(e) { copied = true; + outsideCopyText = ""; var copyText = host.getCopyText(); - if(copyText) + if(copyText) { text.value = copyText; + host.onCopy(); + } else e.preventDefault(); select(); @@ -142,6 +145,7 @@ var TextInput = function(parentNode, host) { var onCut = function(e) { copied = true; + outsideCopyText = ""; var copyText = host.getCopyText(); if(copyText) { text.value = copyText; @@ -154,6 +158,17 @@ var TextInput = function(parentNode, host) { }, 0); }; + // these emit methods can be used for outside of the keyboard command context + this.emitCut = function() { + onCut(); + outsideCopyText = text.value; + } + + this.emitCopy = function() { + onCopy(); + outsideCopyText = text.value; + } + event.addCommandKeyListener(text, host.onCommandKey.bind(host)); if (useragent.isOldIE) { var keytable = { 13:1, 27:1 }; @@ -178,7 +193,10 @@ var TextInput = function(parentNode, host) { // 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")); + if (outsideCopyText.length > 0) + sendText(outsideCopyText); + else + sendText(e.clipboardData.getData("text/plain")); e.preventDefault(); } else {