Fix pasting from the primary selection (#3413)

* Fix clipboard pasting from the primary selection

* Small renaming

* Fix submodules

* Fix pylint false positive
This commit is contained in:
Kris Cherven 2024-09-20 11:00:12 +00:00 committed by GitHub
parent 96ff4f1a4a
commit 0a879bd2ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 7 deletions

View file

@ -192,6 +192,7 @@ Themis Demetriades <themis100@outlook.com>
Luke Bartholomew <lukesbart@icloud.com> Luke Bartholomew <lukesbart@icloud.com>
Gregory Abrasaldo <degeemon@gmail.com> Gregory Abrasaldo <degeemon@gmail.com>
Taylor Obyen <https://github.com/taylorobyen> Taylor Obyen <https://github.com/taylorobyen>
Kris Cherven <krischerven@gmail.com>
******************** ********************

View file

@ -1452,19 +1452,33 @@ class EditorWebView(AnkiWebView):
return not strip_html return not strip_html
def _onPaste(self, mode: QClipboard.Mode) -> None: def _onPaste(self, mode: QClipboard.Mode) -> None:
# Since _on_clipboard_change doesn't always trigger properly on macOS, we do a double check if any changes were made before pasting # Since _on_clipboard_change doesn't always trigger properly on macOS,
# we do a double check if any changes were made before pasting
if self._last_known_clipboard_mime != self.editor.mw.app.clipboard().mimeData(): if self._last_known_clipboard_mime != self.editor.mw.app.clipboard().mimeData():
self._on_clipboard_change() self._on_clipboard_change()
extended = self._wantsExtendedPaste() extended = self._wantsExtendedPaste()
if html := self._internal_field_text_for_paste:
def reuse_internal():
print("reuse internal") print("reuse internal")
if html := self._internal_field_text_for_paste:
self.editor.doPaste(html, True, extended) self.editor.doPaste(html, True, extended)
else: return True
return False
def use_clipboard():
print("use clipboard") print("use clipboard")
mime = self.editor.mw.app.clipboard().mimeData(mode=mode) mime = self.editor.mw.app.clipboard().mimeData(mode=mode)
html, internal = self._processMime(mime, extended) html, internal = self._processMime(mime, extended)
if html: if html:
self.editor.doPaste(html, internal, extended) self.editor.doPaste(html, internal, extended)
return True
return False
if mode == QClipboard.Mode.Selection:
if not use_clipboard():
reuse_internal()
else:
reuse_internal()
def onPaste(self) -> None: def onPaste(self) -> None:
self._onPaste(QClipboard.Mode.Clipboard) self._onPaste(QClipboard.Mode.Clipboard)