mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12: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 doDrop(self, html, internal):
|
||||||
|
def pasteIfField(ret):
|
||||||
|
if ret:
|
||||||
|
self.doPaste(html, internal)
|
||||||
|
|
||||||
|
p = self.web.mapFromGlobal(QCursor.pos())
|
||||||
self.web.evalWithCallback(
|
self.web.evalWithCallback(
|
||||||
"makeDropTargetCurrent();", lambda _: self.doPaste(html, internal)
|
f"focusIfField(document.elementFromPoint({p.x()}, {p.y()}));", pasteIfField
|
||||||
)
|
)
|
||||||
|
|
||||||
def onPaste(self):
|
def onPaste(self):
|
||||||
|
@ -1037,6 +1042,9 @@ class EditorWebView(AnkiWebView):
|
||||||
def onMiddleClickPaste(self) -> None:
|
def onMiddleClickPaste(self) -> None:
|
||||||
self._onPaste(QClipboard.Selection)
|
self._onPaste(QClipboard.Selection)
|
||||||
|
|
||||||
|
def dragEnterEvent(self, evt):
|
||||||
|
evt.accept()
|
||||||
|
|
||||||
def dropEvent(self, evt):
|
def dropEvent(self, evt):
|
||||||
mime = evt.mimeData()
|
mime = evt.mimeData()
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
/* Copyright: Ankitects Pty Ltd and contributors
|
/* Copyright: Ankitects Pty Ltd and contributors
|
||||||
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
|
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
|
||||||
|
|
||||||
import DragOverEvent = JQuery.DragOverEvent;
|
|
||||||
|
|
||||||
let currentField = null;
|
let currentField = null;
|
||||||
let changeTimer = null;
|
let changeTimer = null;
|
||||||
let dropTarget = null;
|
|
||||||
let currentNoteId = null;
|
let currentNoteId = null;
|
||||||
|
|
||||||
declare interface String {
|
declare interface String {
|
||||||
|
@ -219,20 +216,15 @@ function focusPrevious() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onDragOver(elem) {
|
function focusIfField(elem) {
|
||||||
const e = (window.event as unknown) as DragOverEvent;
|
if (elem.classList.contains("field")) {
|
||||||
//e.dataTransfer.dropEffect = "copy";
|
elem.focus();
|
||||||
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 focus event may not fire if the window is not active, so make sure
|
||||||
// the current field is set
|
// the current field is set
|
||||||
currentField = dropTarget;
|
currentField = elem;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPaste(elem) {
|
function onPaste(elem) {
|
||||||
|
@ -366,7 +358,6 @@ function setFields(fields) {
|
||||||
onfocus='onFocus(this);'
|
onfocus='onFocus(this);'
|
||||||
onblur='onBlur();'
|
onblur='onBlur();'
|
||||||
class='field clearfix'
|
class='field clearfix'
|
||||||
ondragover='onDragOver(this);'
|
|
||||||
onpaste='onPaste(this);'
|
onpaste='onPaste(this);'
|
||||||
oncopy='onCutOrCopy(this);'
|
oncopy='onCutOrCopy(this);'
|
||||||
oncut='onCutOrCopy(this);'
|
oncut='onCutOrCopy(this);'
|
||||||
|
|
Loading…
Reference in a new issue