From 151f854fa2e5211c36a11bb9c10406eba07ae22e Mon Sep 17 00:00:00 2001 From: abdo Date: Mon, 14 Sep 2020 17:07:31 +0300 Subject: [PATCH] Support extended drag & drop --- CONTRIBUTORS | 2 +- qt/aqt/editor.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index b0ab64c5f..b36c6b209 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -54,7 +54,7 @@ neitrinoweb Andreas Reis Matt Krump Alexander Presnyakov -abdo +abdo aplaice phwoo Soren Bjornstad diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 05d57d507..6aeb41743 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -923,7 +923,7 @@ to a cloze type first, via 'Notes>Change Note Type'""" def doDrop(self, html, internal): def pasteIfField(ret): if ret: - self.doPaste(html, internal) + self.doPaste(html, internal, self.web._wantsExtendedPaste()) p = self.web.mapFromGlobal(QCursor.pos()) self.web.evalWithCallback(f"focusIfField({p.x()}, {p.y()});", pasteIfField) @@ -1028,10 +1028,14 @@ class EditorWebView(AnkiWebView): def onCopy(self): self.triggerPageAction(QWebEnginePage.Copy) - def _onPaste(self, mode: QClipboard.Mode) -> None: + def _wantsExtendedPaste(self) -> bool: extended = not (self.editor.mw.app.queryKeyboardModifiers() & Qt.ShiftModifier) if self.editor.mw.pm.profile.get("pasteInvert", False): extended = not extended + return extended + + def _onPaste(self, mode: QClipboard.Mode) -> None: + extended = self._wantsExtendedPaste() mime = self.editor.mw.app.clipboard().mimeData(mode=mode) html, internal = self._processMime(mime) if not html: