From 980fbd32d63bd38e3bb8102d86ecfccb1a35bc83 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Fri, 24 Sep 2010 08:44:13 -0400 Subject: [PATCH] Send an "input" event when pasting into an element. Fixes issue #17. --- common/content/editor.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/common/content/editor.js b/common/content/editor.js index 03091813..b8235607 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -62,7 +62,11 @@ const Editor = Module("editor", { // FIXME: #93 ( in the bottom of a long textarea bounces up) let elem = dactyl.focus; - if (elem.setSelectionRange && dactyl.clipboardRead()) { + if (elem.setSelectionRange) { + let text = dactyl.clipboardRead(); + if (!text) + return; + // clipboardRead would return 'undefined' if not checked // dunno about .setSelectionRange // This is a hacky fix - but it works. @@ -72,7 +76,7 @@ const Editor = Module("editor", { let rangeStart = elem.selectionStart; // caret position let rangeEnd = elem.selectionEnd; let tempStr1 = elem.value.substring(0, rangeStart); - let tempStr2 = dactyl.clipboardRead() || ""; + let tempStr2 = text; let tempStr3 = elem.value.substring(rangeEnd); elem.value = tempStr1 + tempStr2 + tempStr3; elem.selectionStart = rangeStart + tempStr2.length; @@ -80,6 +84,9 @@ const Editor = Module("editor", { elem.scrollTop = curTop; elem.scrollLeft = curLeft; + let event = elem.ownerDocument.createEvent("Event"); + event.initEvent("input", true, false); + elem.dispatchEvent(event); } },