diff options
author | Kris Maglione <maglione.k@gmail.com> | 2011-10-04 23:15:58 -0400 |
---|---|---|
committer | Kris Maglione <maglione.k@gmail.com> | 2011-10-04 23:15:58 -0400 |
commit | 1af7252f349ec45861fc089e75b7f079c6f432ab (patch) | |
tree | ad1a3f140114977b2599b9e0cdae07d1aa8ad930 | |
parent | 313b31756b830605a5492a69324c925675d96537 (diff) | |
download | pentadactyl-1af7252f349ec45861fc089e75b7f079c6f432ab.tar.gz |
Sanify editor.pasteClipboard.
-rw-r--r-- | common/content/editor.js | 34 |
1 files changed, 5 insertions, 29 deletions
diff --git a/common/content/editor.js b/common/content/editor.js index e5513222..2de8cd33 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -68,37 +68,13 @@ var Editor = Module("editor", { this.editor.setShouldTxnSetSelection(!val); }, - pasteClipboard: function (clipboard, toStart) { + pasteClipboard: function pasteClipboard(clipboard) { let elem = this.element; - if (elem.setSelectionRange) { - let text = dactyl.clipboardRead(clipboard); - if (!text) - return; - if (isinstance(elem, [HTMLInputElement, XULTextBoxElement])) - text = text.replace(/\n+/g, ""); - - // This is a hacky fix - but it works. - // <s-insert> in the bottom of a long textarea bounces up - let top = elem.scrollTop; - let left = elem.scrollLeft; - - let start = elem.selectionStart; // caret position - let end = elem.selectionEnd; - let value = elem.value.substring(0, start) + text + elem.value.substring(end); - elem.value = value; - - if (/^(search|text)$/.test(elem.type)) - DOM(elem).editor.rootElement.firstChild.textContent = value; + let text = dactyl.clipboardRead(clipboard); + dactyl.assert(text && this.editor instanceof Ci.nsIPlaintextEditor); - elem.selectionStart = Math.min(start + (toStart ? 0 : text.length), elem.value.length); - elem.selectionEnd = elem.selectionStart; - - elem.scrollTop = top; - elem.scrollLeft = left; - - DOM(elem).input(); - } + this.editor.insertText(text); }, // count is optional, defaults to 1 @@ -138,7 +114,6 @@ var Editor = Module("editor", { this.selection[select ? "extend" : "collapse"](node, pos); }, - mungeRange: function mungeRange(range, munger, selectEnd) { let { editor } = this; editor.beginPlaceHolderTransaction(null); @@ -187,6 +162,7 @@ var Editor = Module("editor", { }, findChar: function (key, count, backward) { + // TODO: Use extendRange, return range. util.assert(DOM(this.element).isInput); |