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

@ -163,7 +163,7 @@ Lucas Scharenbroch <lucasscharenbroch@gmail.com>
Antonio Cavallo <a.cavallo@cavallinux.eu>
Han Yeong-woo <han@yeongwoo.dev>
Jean Khawand <jk@jeankhawand.com>
Pedro Schreiber <schreiber.mmb@gmail.com>
Pedro Schreiber <schreiber.mmb@gmail.com>
Foxy_null <https://github.com/Foxy-null>
Arbyste <arbyste@outlook.com>
Vasll <github.com/vasll>
@ -187,11 +187,12 @@ Christian Donat <https://github.com/cdonat2>
Asuka Minato <https://asukaminato.eu.org>
Dillon Baldwin <https://github.com/DillBal>
Voczi <https://github.com/voczi>
Ben Nguyen <105088397+bpnguyen107@users.noreply.github.com>
Ben Nguyen <105088397+bpnguyen107@users.noreply.github.com>
Themis Demetriades <themis100@outlook.com>
Luke Bartholomew <lukesbart@icloud.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
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():
self._on_clipboard_change()
extended = self._wantsExtendedPaste()
if html := self._internal_field_text_for_paste:
def reuse_internal():
print("reuse internal")
self.editor.doPaste(html, True, extended)
else:
if html := self._internal_field_text_for_paste:
self.editor.doPaste(html, True, extended)
return True
return False
def use_clipboard():
print("use clipboard")
mime = self.editor.mw.app.clipboard().mimeData(mode=mode)
html, internal = self._processMime(mime, extended)
if html:
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:
self._onPaste(QClipboard.Mode.Clipboard)