paste-primary: fix undo/redo not working
It seems that unlike Gecko, WebKit does not support undo/redo operations when the textarea's `value` attribute is changed directly. Fortunately there is a WebKit-specific workaround using textInput event. References: * http://stackoverflow.com/a/7554295 * http://help.dottoro.com/ljuecqgv.php
This commit is contained in:
parent
4d7e39470e
commit
35e16a8e6e
@ -1324,21 +1324,14 @@ class CommandDispatcher:
|
|||||||
clipboard = QApplication.clipboard()
|
clipboard = QApplication.clipboard()
|
||||||
if clipboard.supportsSelection():
|
if clipboard.supportsSelection():
|
||||||
sel = clipboard.text(QClipboard.Selection)
|
sel = clipboard.text(QClipboard.Selection)
|
||||||
log.misc.debug("Pasting selection: '{}'".format(sel))
|
log.misc.debug("Pasting primary selection into element {} "
|
||||||
|
"(selection is '{}')".format(elem.debug_text(), sel))
|
||||||
elem.evaluateJavaScript("""
|
elem.evaluateJavaScript("""
|
||||||
var sel = '%s';
|
var sel = '{}';
|
||||||
if (this.selectionStart || this.selectionStart == '0') {
|
var event = document.createEvent('TextEvent');
|
||||||
var startPos = this.selectionStart;
|
event.initTextEvent('textInput', true, true, null, sel);
|
||||||
var endPos = this.selectionEnd;
|
this.dispatchEvent(event);
|
||||||
this.value = this.value.substring(0, startPos)
|
""".format(sel))
|
||||||
+ sel
|
|
||||||
+ this.value.substring(endPos, this.value.length);
|
|
||||||
this.selectionStart = startPos + sel.length;
|
|
||||||
this.selectionEnd = startPos + sel.length;
|
|
||||||
} else {
|
|
||||||
this.value += sel;
|
|
||||||
}
|
|
||||||
""" % sel)
|
|
||||||
|
|
||||||
def _clear_search(self, view, text):
|
def _clear_search(self, view, text):
|
||||||
"""Clear search string/highlights for the given view.
|
"""Clear search string/highlights for the given view.
|
||||||
|
Loading…
Reference in New Issue
Block a user