Skip to content

Commit

Permalink
Fix pasting from the primary selection (ankitects#3413)
Browse files Browse the repository at this point in the history
* Fix clipboard pasting from the primary selection

* Small renaming

* Fix submodules

* Fix pylint false positive
  • Loading branch information
krischerven authored and twwn committed Sep 22, 2024
1 parent 0f2355f commit 0e7f54d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
7 changes: 4 additions & 3 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>

********************

Expand Down
22 changes: 18 additions & 4 deletions qt/aqt/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,19 +1452,33 @@ def _wantsExtendedPaste(self) -> bool:
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)
Expand Down

0 comments on commit 0e7f54d

Please sign in to comment.