From a7ed7fa4e330eb108492dc86a9d7714a647854e9 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 2 Sep 2017 13:48:03 +1000 Subject: [PATCH] fix cutting and copying between fields the shortcut keys are handled by webengine on platforms other than osx, so rather than messing with an event filter we catch the cut and copy events in js and send a signal back --- aqt/editor.py | 10 ++++++++-- web/editor.js | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index b14825079..f54740fbe 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -646,6 +646,9 @@ to a cloze type first, via Edit>Change Note Type.""")) def onPaste(self): self.web.onPaste() + def onCutOrCopy(self): + self.web.flagAnkiText() + # Advanced menu ###################################################################### @@ -693,6 +696,7 @@ to a cloze type first, via Edit>Change Note Type.""")) more=onAdvanced, dupes=showDupes, paste=onPaste, + cutOrCopy=onCutOrCopy, ) # Pasting, drag & drop, and keyboard layouts @@ -715,11 +719,9 @@ class EditorWebView(AnkiWebView): self._flagAnkiText() def onCut(self): - self._markInternal = True self.triggerPageAction(QWebEnginePage.Cut) def onCopy(self): - self._markInternal = True self.triggerPageAction(QWebEnginePage.Copy) def onPaste(self): @@ -819,6 +821,10 @@ class EditorWebView(AnkiWebView): # add to media and return resulting html link return self.editor._addMedia(newpath) + def flagAnkiText(self): + # be ready to adjust when clipboard event fires + self._markInternal = True + def _flagAnkiText(self): # add a comment in the clipboard html so we can tell text is copied # from us and doesn't need to be stripped diff --git a/web/editor.js b/web/editor.js index 14df3bdcc..8bed7ae9d 100644 --- a/web/editor.js +++ b/web/editor.js @@ -258,6 +258,11 @@ function wrap(front, back) { } } +function onCutOrCopy() { + pycmd("cutOrCopy"); + return true; +} + function setFields(fields, prewrap) { var txt = ""; for (var i = 0; i < fields.length; i++) { @@ -270,6 +275,7 @@ function setFields(fields, prewrap) { txt += "