mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
work around editor freeze issue after external drag & drop
This commit is contained in:
parent
d266f9a80a
commit
680b5e4b50
2 changed files with 18 additions and 19 deletions
|
@ -917,8 +917,13 @@ to a cloze type first, via 'Notes>Change Note Type'"""
|
|||
)
|
||||
|
||||
def doDrop(self, html, internal):
|
||||
def pasteIfField(ret):
|
||||
if ret:
|
||||
self.doPaste(html, internal)
|
||||
|
||||
p = self.web.mapFromGlobal(QCursor.pos())
|
||||
self.web.evalWithCallback(
|
||||
"makeDropTargetCurrent();", lambda _: self.doPaste(html, internal)
|
||||
f"focusIfField(document.elementFromPoint({p.x()}, {p.y()}));", pasteIfField
|
||||
)
|
||||
|
||||
def onPaste(self):
|
||||
|
@ -1037,6 +1042,9 @@ class EditorWebView(AnkiWebView):
|
|||
def onMiddleClickPaste(self) -> None:
|
||||
self._onPaste(QClipboard.Selection)
|
||||
|
||||
def dragEnterEvent(self, evt):
|
||||
evt.accept()
|
||||
|
||||
def dropEvent(self, evt):
|
||||
mime = evt.mimeData()
|
||||
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
/* Copyright: Ankitects Pty Ltd and contributors
|
||||
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
|
||||
|
||||
import DragOverEvent = JQuery.DragOverEvent;
|
||||
|
||||
let currentField = null;
|
||||
let changeTimer = null;
|
||||
let dropTarget = null;
|
||||
let currentNoteId = null;
|
||||
|
||||
declare interface String {
|
||||
|
@ -219,20 +216,15 @@ function focusPrevious() {
|
|||
}
|
||||
}
|
||||
|
||||
function onDragOver(elem) {
|
||||
const e = (window.event as unknown) as DragOverEvent;
|
||||
//e.dataTransfer.dropEffect = "copy";
|
||||
e.preventDefault();
|
||||
// if we focus the target element immediately, the drag&drop turns into a
|
||||
// copy, so note it down for later instead
|
||||
dropTarget = elem;
|
||||
}
|
||||
|
||||
function makeDropTargetCurrent() {
|
||||
dropTarget.focus();
|
||||
// the focus event may not fire if the window is not active, so make sure
|
||||
// the current field is set
|
||||
currentField = dropTarget;
|
||||
function focusIfField(elem) {
|
||||
if (elem.classList.contains("field")) {
|
||||
elem.focus();
|
||||
// the focus event may not fire if the window is not active, so make sure
|
||||
// the current field is set
|
||||
currentField = elem;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function onPaste(elem) {
|
||||
|
@ -366,7 +358,6 @@ function setFields(fields) {
|
|||
onfocus='onFocus(this);'
|
||||
onblur='onBlur();'
|
||||
class='field clearfix'
|
||||
ondragover='onDragOver(this);'
|
||||
onpaste='onPaste(this);'
|
||||
oncopy='onCutOrCopy(this);'
|
||||
oncut='onCutOrCopy(this);'
|
||||
|
|
Loading…
Reference in a new issue