fix drag & drop issue when dropping things over existing content

This commit is contained in:
ANH 2020-08-25 17:23:34 +03:00
parent dee7d45d8b
commit cc17b4db62
2 changed files with 12 additions and 10 deletions

View file

@ -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()

View file

@ -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;
}