mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Fix JS drop event not firing in the reviewer (#1906)
* Allow webviews to opt in to default D&D handling * Remove redundant webview.js include * Block default drag & drop behavior in reviewing screens * Fix mypy error
This commit is contained in:
parent
f15e294981
commit
1bab947c9c
6 changed files with 24 additions and 2 deletions
|
@ -132,6 +132,8 @@ class Previewer(QDialog):
|
||||||
],
|
],
|
||||||
context=self,
|
context=self,
|
||||||
)
|
)
|
||||||
|
self._web.allow_drops = True
|
||||||
|
self._web.eval("_blockDefaultDragDropBehavior();")
|
||||||
self._web.set_bridge_command(self._on_bridge_cmd, self)
|
self._web.set_bridge_command(self._on_bridge_cmd, self)
|
||||||
|
|
||||||
def _on_bridge_cmd(self, cmd: str) -> Any:
|
def _on_bridge_cmd(self, cmd: str) -> Any:
|
||||||
|
|
|
@ -355,6 +355,8 @@ class CardLayout(QDialog):
|
||||||
],
|
],
|
||||||
context=self,
|
context=self,
|
||||||
)
|
)
|
||||||
|
self.preview_web.allow_drops = True
|
||||||
|
self.preview_web.eval("_blockDefaultDragDropBehavior();")
|
||||||
self.preview_web.set_bridge_command(self._on_bridge_cmd, self)
|
self.preview_web.set_bridge_command(self._on_bridge_cmd, self)
|
||||||
|
|
||||||
if self._isCloze():
|
if self._isCloze():
|
||||||
|
|
|
@ -313,6 +313,9 @@ class Reviewer:
|
||||||
],
|
],
|
||||||
context=self,
|
context=self,
|
||||||
)
|
)
|
||||||
|
# block default drag & drop behavior while allowing drop events to be received by JS handlers
|
||||||
|
self.web.allow_drops = True
|
||||||
|
self.web.eval("_blockDefaultDragDropBehavior();")
|
||||||
# show answer / ease buttons
|
# show answer / ease buttons
|
||||||
self.bottom.web.show()
|
self.bottom.web.show()
|
||||||
self.bottom.web.stdHtml(
|
self.bottom.web.stdHtml(
|
||||||
|
|
|
@ -47,7 +47,7 @@ class Toolbar:
|
||||||
self.web.stdHtml(
|
self.web.stdHtml(
|
||||||
self._body % self._centerLinks(),
|
self._body % self._centerLinks(),
|
||||||
css=["css/toolbar.css"],
|
css=["css/toolbar.css"],
|
||||||
js=["js/webview.js", "js/vendor/jquery.min.js", "js/toolbar.js"],
|
js=["js/vendor/jquery.min.js", "js/toolbar.js"],
|
||||||
context=web_context,
|
context=web_context,
|
||||||
)
|
)
|
||||||
self.web.adjustHeightToFit()
|
self.web.adjustHeightToFit()
|
||||||
|
|
|
@ -222,6 +222,8 @@ class WebContent:
|
||||||
|
|
||||||
|
|
||||||
class AnkiWebView(QWebEngineView):
|
class AnkiWebView(QWebEngineView):
|
||||||
|
allow_drops = False
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
parent: Optional[QWidget] = None,
|
parent: Optional[QWidget] = None,
|
||||||
|
@ -322,7 +324,8 @@ class AnkiWebView(QWebEngineView):
|
||||||
m.popup(QCursor.pos())
|
m.popup(QCursor.pos())
|
||||||
|
|
||||||
def dropEvent(self, evt: QDropEvent) -> None:
|
def dropEvent(self, evt: QDropEvent) -> None:
|
||||||
pass
|
if self.allow_drops:
|
||||||
|
super().dropEvent(evt)
|
||||||
|
|
||||||
def setHtml(self, html: str) -> None: # type: ignore
|
def setHtml(self, html: str) -> None: # type: ignore
|
||||||
# discard any previous pending actions
|
# discard any previous pending actions
|
||||||
|
@ -331,6 +334,7 @@ class AnkiWebView(QWebEngineView):
|
||||||
self._queueAction("setHtml", html)
|
self._queueAction("setHtml", html)
|
||||||
self.set_open_links_externally(True)
|
self.set_open_links_externally(True)
|
||||||
self.setZoomFactor(1)
|
self.setZoomFactor(1)
|
||||||
|
self.allow_drops = False
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def _setHtml(self, html: str) -> None:
|
def _setHtml(self, html: str) -> None:
|
||||||
|
@ -357,6 +361,7 @@ class AnkiWebView(QWebEngineView):
|
||||||
def load_url(self, url: QUrl) -> None:
|
def load_url(self, url: QUrl) -> None:
|
||||||
# allow queuing actions when loading url directly
|
# allow queuing actions when loading url directly
|
||||||
self._domDone = False
|
self._domDone = False
|
||||||
|
self.allow_drops = False
|
||||||
super().load(url)
|
super().load(url)
|
||||||
|
|
||||||
def app_zoom_factor(self) -> float:
|
def app_zoom_factor(self) -> float:
|
||||||
|
|
|
@ -227,3 +227,13 @@ export function _typeAnsPress(): void {
|
||||||
export function _emulateMobile(enabled: boolean): void {
|
export function _emulateMobile(enabled: boolean): void {
|
||||||
document.documentElement.classList.toggle("mobile", enabled);
|
document.documentElement.classList.toggle("mobile", enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Block Qt's default drag & drop behavior by default
|
||||||
|
export function _blockDefaultDragDropBehavior(): void {
|
||||||
|
function handler(evt: DragEvent) {
|
||||||
|
evt.preventDefault();
|
||||||
|
}
|
||||||
|
document.ondragenter = handler;
|
||||||
|
document.ondragover = handler;
|
||||||
|
document.ondrop = handler;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue