mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
don't strip html when pasting from field to field
This commit is contained in:
parent
4b181d0cfb
commit
5cd6b830ed
1 changed files with 20 additions and 2 deletions
|
@ -875,8 +875,12 @@ class EditorWebView(AnkiWebView):
|
||||||
and evt.key() == Qt.Key_V)
|
and evt.key() == Qt.Key_V)
|
||||||
if evt.matches(QKeySequence.Paste) or shiftPaste:
|
if evt.matches(QKeySequence.Paste) or shiftPaste:
|
||||||
self.prepareClip(shiftPaste)
|
self.prepareClip(shiftPaste)
|
||||||
if shiftPaste:
|
if shiftPaste:
|
||||||
self.triggerPageAction(QWebPage.Paste)
|
self.triggerPageAction(QWebPage.Paste)
|
||||||
|
elif evt.matches(QKeySequence.Copy):
|
||||||
|
self.triggerPageAction(QWebPage.Copy)
|
||||||
|
self._flagAnkiText()
|
||||||
|
return evt.accept()
|
||||||
QWebView.keyPressEvent(self, evt)
|
QWebView.keyPressEvent(self, evt)
|
||||||
self.restoreClip()
|
self.restoreClip()
|
||||||
|
|
||||||
|
@ -920,6 +924,10 @@ class EditorWebView(AnkiWebView):
|
||||||
def prepareClip(self, keep=False, mode=QClipboard.Clipboard):
|
def prepareClip(self, keep=False, mode=QClipboard.Clipboard):
|
||||||
clip = self.editor.mw.app.clipboard()
|
clip = self.editor.mw.app.clipboard()
|
||||||
mime = clip.mimeData(mode=mode)
|
mime = clip.mimeData(mode=mode)
|
||||||
|
if mime.hasHtml() and mime.html().startswith("<!--anki-->"):
|
||||||
|
# pasting from another field
|
||||||
|
mime.setHtml(mime.html()[11:])
|
||||||
|
return
|
||||||
self.saveClip(mode=mode)
|
self.saveClip(mode=mode)
|
||||||
if keep:
|
if keep:
|
||||||
new = QMimeData()
|
new = QMimeData()
|
||||||
|
@ -1039,3 +1047,13 @@ class EditorWebView(AnkiWebView):
|
||||||
file.write(filecontents)
|
file.write(filecontents)
|
||||||
file.close()
|
file.close()
|
||||||
return self.editor._addMedia(path)
|
return self.editor._addMedia(path)
|
||||||
|
|
||||||
|
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
|
||||||
|
clip = self.editor.mw.app.clipboard()
|
||||||
|
mime = clip.mimeData()
|
||||||
|
if not mime.hasHtml():
|
||||||
|
return
|
||||||
|
html = mime.html()
|
||||||
|
mime.setHtml("<!--anki-->" + mime.html())
|
||||||
|
|
Loading…
Reference in a new issue