mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 17:57:59 +01:00
Sanify editor.pasteClipboard.
This commit is contained in:
@@ -68,37 +68,13 @@ var Editor = Module("editor", {
|
|||||||
this.editor.setShouldTxnSetSelection(!val);
|
this.editor.setShouldTxnSetSelection(!val);
|
||||||
},
|
},
|
||||||
|
|
||||||
pasteClipboard: function (clipboard, toStart) {
|
pasteClipboard: function pasteClipboard(clipboard) {
|
||||||
let elem = this.element;
|
let elem = this.element;
|
||||||
|
|
||||||
if (elem.setSelectionRange) {
|
let text = dactyl.clipboardRead(clipboard);
|
||||||
let text = dactyl.clipboardRead(clipboard);
|
dactyl.assert(text && this.editor instanceof Ci.nsIPlaintextEditor);
|
||||||
if (!text)
|
|
||||||
return;
|
|
||||||
if (isinstance(elem, [HTMLInputElement, XULTextBoxElement]))
|
|
||||||
text = text.replace(/\n+/g, "");
|
|
||||||
|
|
||||||
// This is a hacky fix - but it works.
|
this.editor.insertText(text);
|
||||||
// <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;
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// count is optional, defaults to 1
|
// count is optional, defaults to 1
|
||||||
@@ -138,7 +114,6 @@ var Editor = Module("editor", {
|
|||||||
this.selection[select ? "extend" : "collapse"](node, pos);
|
this.selection[select ? "extend" : "collapse"](node, pos);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
mungeRange: function mungeRange(range, munger, selectEnd) {
|
mungeRange: function mungeRange(range, munger, selectEnd) {
|
||||||
let { editor } = this;
|
let { editor } = this;
|
||||||
editor.beginPlaceHolderTransaction(null);
|
editor.beginPlaceHolderTransaction(null);
|
||||||
@@ -187,6 +162,7 @@ var Editor = Module("editor", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
findChar: function (key, count, backward) {
|
findChar: function (key, count, backward) {
|
||||||
|
// TODO: Use extendRange, return range.
|
||||||
|
|
||||||
util.assert(DOM(this.element).isInput);
|
util.assert(DOM(this.element).isInput);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user