From cc17b4db622747f9654fc335544251a3965b64b1 Mon Sep 17 00:00:00 2001 From: ANH Date: Tue, 25 Aug 2020 17:23:34 +0300 Subject: [PATCH] fix drag & drop issue when dropping things over existing content --- qt/aqt/editor.py | 4 +--- qt/ts/src/editor.ts | 18 +++++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 2785f9c3a..b9d15a221 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -922,9 +922,7 @@ to a cloze type first, via 'Notes>Change Note Type'""" self.doPaste(html, internal) p = self.web.mapFromGlobal(QCursor.pos()) - self.web.evalWithCallback( - f"focusIfField(document.elementFromPoint({p.x()}, {p.y()}));", pasteIfField - ) + self.web.evalWithCallback(f"focusIfField({p.x()}, {p.y()});", pasteIfField) def onPaste(self): self.web.onPaste() diff --git a/qt/ts/src/editor.ts b/qt/ts/src/editor.ts index 774a9d019..aafc63efb 100644 --- a/qt/ts/src/editor.ts +++ b/qt/ts/src/editor.ts @@ -216,13 +216,17 @@ function focusPrevious() { } } -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; +function focusIfField(x, y) { + const elements = document.elementsFromPoint(x, y); + for (let i = 0; i < elements.length; i++) { + let elem = elements[i] as HTMLElement; + 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; }