From 174a2e7bc53541961c0896c7d041f03adb7b4813 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 11 Dec 2023 12:27:41 +1000 Subject: [PATCH] Revert "Prefer image pastes over HTML in the editor (#2856)" This reverts commit abd8759d502bea5707661d17b06787e395794156. Rolling this back for now, as it's caused a couple of regressions: - In the old path, we returned (html, internal=False); in the new path, it's returned as internal=True, which prevents formatting from being stripped. This requires night mode to reproduce, as we don't strip text colors in day mode. - It can result in lost alt tags and filenames, as after right clicking on an image in Chrome and choosing 'copy image', Chrome puts both the HTML and the image on the clipboard Related discussion: https://forums.ankiweb.net/t/anki-23-12-beta/37771/90 --- qt/aqt/editor.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 86fc097b5..0b3dc1e3c 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -1490,29 +1490,26 @@ class EditorWebView(AnkiWebView): # print("urls", mime.urls()) # print("text", mime.text()) + internal = False + mime = gui_hooks.editor_will_process_mime( - mime, self, False, extended, drop_event + mime, self, internal, extended, drop_event ) + # try various content types in turn + if mime.hasHtml(): + html_content = mime.html()[11:] if internal else mime.html() + return html_content, internal + # favour url if it's a local link if ( mime.hasUrls() and (urls := mime.urls()) and urls[0].toString().startswith("file://") ): - types = ( - self._processUrls, - self._processImage, - self._processHtml, - self._processText, - ) + types = (self._processUrls, self._processImage, self._processText) else: - types = ( - self._processImage, - self._processHtml, - self._processUrls, - self._processText, - ) + types = (self._processImage, self._processUrls, self._processText) for fn in types: html = fn(mime, extended) @@ -1534,11 +1531,6 @@ class EditorWebView(AnkiWebView): return buf - def _processHtml(self, mime: QMimeData, extended: bool = False) -> str | None: - if mime.hasHtml(): - return mime.html() - return None - def _processText(self, mime: QMimeData, extended: bool = False) -> str | None: if not mime.hasText(): return None