Description
Hello! I encountered a bug in the DOM observer logic. The setup: I have a custom element webwriter-choice
(becoming a node webwriter_choice
) and an element webwriter-choice-item
(webwriter_choice_item
). Then, I have this logic on webwriter-choice
:
const choiceItem = this.ownerDocument.createElement("webwriter-choice-item")
const p = this.ownerDocument.createElement("p")
choiceItem.appendChild(p)
this.appendChild(choiceItem)
this.ownerDocument.getSelection().setBaseAndExtent(p, 0, p, 0)
This works fine outside of ProseMirror. Inside a ProseMirror view, it breaks exactly when the selection is at the end of the previous item (see GIFs below).
I am sure the heuristic added in #175 is the problem. I specifically found that if I remove the heuristic, the issue doesn't occur at all. EDIT: Not true, see below.
With the heuristic
if (((browser.ios && view.input.lastIOSEnter > Date.now() - 225 &&
(!inlineChange || addedNodes.some(n => n.nodeName == "DIV" || n.nodeName == "P"))) ||
(!inlineChange && $from.pos < parse.doc.content.size && !$from.sameParent($to) &&
(nextSel = Selection.findFrom(parse.doc.resolve($from.pos + 1), 1, true)) &&
nextSel.head == $to.pos)) &&
view.someProp("handleKeyDown", f => f(view, keyEvent(13, "Enter")))) {
view.input.lastIOSEnter = 0
return
}
Without the heuristic
if ((browser.ios && view.input.lastIOSEnter > Date.now() - 225 &&
(!inlineChange || addedNodes.some(n => n.nodeName == "DIV" || n.nodeName == "P"))) &&
view.someProp("handleKeyDown", f => f(view, keyEvent(13, "Enter")))) {
view.input.lastIOSEnter = 0
return
}
Possible solutions
The heuristic is from 2016 - is it still needed 8 years later? Otherwise, it might be worth improving since this is close to impossible to work around in user land (can't disable it, can't influence the DOM reading process).
Platform info
- "prosemirror-view": "1.33.8"
- OS: Windows 10.0.19045 X64
- WebView2: 126.0.2592.113 (basically Chromium, running in Tauri)
Activity