prevent cmd+c in webview with empty selection from crashing on macOS

https://forums.ankiweb.net/t/command-c-on-crashes-anki-2-1-41-on-mac/10684
This commit is contained in:
Damien Elmes 2021-06-11 19:58:20 +10:00
parent 18f8e3743b
commit d448bd9cb6

View file

@ -288,9 +288,11 @@ class AnkiWebView(QWebEngineView):
def onCopy(self) -> None: def onCopy(self) -> None:
if not self.selectedText(): if not self.selectedText():
ctx = self._page.contextMenuData() if not isMac:
if ctx and ctx.mediaType() == QWebEngineContextMenuData.MediaTypeImage: # crashes on a mac when clicking in the main window and pressing cmd+c
self.triggerPageAction(QWebEnginePage.CopyImageToClipboard) ctx = self._page.contextMenuData()
if ctx and ctx.mediaType() == QWebEngineContextMenuData.MediaTypeImage:
self.triggerPageAction(QWebEnginePage.CopyImageToClipboard)
else: else:
self.triggerPageAction(QWebEnginePage.Copy) self.triggerPageAction(QWebEnginePage.Copy)