mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-06 21:25:45 +01:00
Clean up editor.pasteClipboard.
--HG-- extra : rebase_source : 119ea139b97eee94ec195ddf251c00d5ebdf81c0
This commit is contained in:
@@ -24,12 +24,12 @@ const Editor = Module("editor", {
|
|||||||
selectedText: function () String(Editor.getEditor(null).selection),
|
selectedText: function () String(Editor.getEditor(null).selection),
|
||||||
|
|
||||||
pasteClipboard: function (clipboard, toStart) {
|
pasteClipboard: function (clipboard, toStart) {
|
||||||
|
// TODO: I don't think this is needed anymore? --djk
|
||||||
if (util.OS.isWindows) {
|
if (util.OS.isWindows) {
|
||||||
this.executeCommand("cmd_paste");
|
this.executeCommand("cmd_paste");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: #93 (<s-insert> in the bottom of a long textarea bounces up)
|
|
||||||
let elem = dactyl.focus;
|
let elem = dactyl.focus;
|
||||||
|
|
||||||
if (elem.setSelectionRange) {
|
if (elem.setSelectionRange) {
|
||||||
@@ -37,23 +37,20 @@ const Editor = Module("editor", {
|
|||||||
if (!text)
|
if (!text)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// clipboardRead would return 'undefined' if not checked
|
|
||||||
// dunno about .setSelectionRange
|
|
||||||
// This is a hacky fix - but it works.
|
// This is a hacky fix - but it works.
|
||||||
let curTop = elem.scrollTop;
|
// <s-insert> in the bottom of a long textarea bounces up
|
||||||
let curLeft = elem.scrollLeft;
|
let top = elem.scrollTop;
|
||||||
|
let left = elem.scrollLeft;
|
||||||
|
|
||||||
let rangeStart = elem.selectionStart; // caret position
|
let start = elem.selectionStart; // caret position
|
||||||
let rangeEnd = elem.selectionEnd;
|
let end = elem.selectionEnd;
|
||||||
let tempStr1 = elem.value.substring(0, rangeStart);
|
elem.value = elem.value.substring(0, start) + text + elem.value.substring(end);
|
||||||
let tempStr2 = text;
|
elem.selectionStart = start + (toStart ? 0 : text.length);
|
||||||
let tempStr3 = elem.value.substring(rangeEnd);
|
|
||||||
elem.value = tempStr1 + tempStr2 + tempStr3;
|
|
||||||
elem.selectionStart = rangeStart + (toStart ? 0 : tempStr2.length);
|
|
||||||
elem.selectionEnd = elem.selectionStart;
|
elem.selectionEnd = elem.selectionStart;
|
||||||
|
|
||||||
elem.scrollTop = curTop;
|
elem.scrollTop = top;
|
||||||
elem.scrollLeft = curLeft;
|
elem.scrollLeft = left;
|
||||||
|
|
||||||
let event = elem.ownerDocument.createEvent("Event");
|
let event = elem.ownerDocument.createEvent("Event");
|
||||||
event.initEvent("input", true, false);
|
event.initEvent("input", true, false);
|
||||||
events.dispatch(elem, event);
|
events.dispatch(elem, event);
|
||||||
|
|||||||
Reference in New Issue
Block a user