From f9f8b117d97ac80f5cd5ec9d9a9099f2166ae242 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 31 Aug 2017 18:10:37 +1000 Subject: [PATCH] fix formatting preservation when pasting between fields - make sure js is passed the internal flag - make sure we flag text after the asynchronous clipboard change - be explicit about clipboard data update --- aqt/editor.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index cd6f910d3..dbefc5f87 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -637,7 +637,8 @@ to a cloze type first, via Edit>Change Note Type.""")) def doPaste(self, html, internal): if not internal: html = self._pastePreFilter(html) - self.web.eval("pasteHTML(%s);" % json.dumps(html)) + self.web.eval("pasteHTML(%s, %s);" % ( + json.dumps(html), json.dumps(internal))) def doDrop(self, html, internal): self.web.evalWithCallback("makeDropTargetCurrent();", @@ -705,14 +706,22 @@ class EditorWebView(AnkiWebView): self.editor = editor self.strip = self.editor.mw.pm.profile['stripHTML'] self.setAcceptDrops(True) + self._markInternal = False + clip = self.editor.mw.app.clipboard() + clip.dataChanged.connect(self._onClipboardChange) + + def _onClipboardChange(self): + if self._markInternal: + self._markInternal = False + self._flagAnkiText() def onCut(self): + self._markInternal = True self.triggerPageAction(QWebEnginePage.Cut) - self._flagAnkiText() def onCopy(self): + self._markInternal = True self.triggerPageAction(QWebEnginePage.Copy) - self._flagAnkiText() def onPaste(self): mime = self.editor.mw.app.clipboard().mimeData(mode=QClipboard.Clipboard) @@ -819,7 +828,8 @@ class EditorWebView(AnkiWebView): if not mime.hasHtml(): return html = mime.html() - mime.setHtml("" + mime.html()) + mime.setHtml("" + html) + clip.setMimeData(mime) def contextMenuEvent(self, evt): m = QMenu(self)