diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 5f2c5e8de..2785f9c3a 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -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() diff --git a/qt/ts/src/editor.ts b/qt/ts/src/editor.ts index ca6cf5742..774a9d019 100644 --- a/qt/ts/src/editor.ts +++ b/qt/ts/src/editor.ts @@ -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);'