ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.53k stars 334 forks source link

Firefox: backspace at end of list item with one character following an unselectable atom triggers Enter instead #1464

Closed mayacoda closed 2 months ago

mayacoda commented 2 months ago

When pressing backspace at the end of a list item that has an inline, unselectable atom node followed by a text node with a single character, trying to delete that character with Backspace triggers a keydown event with Enter instead.

This only happens in Firefox. It's not clear in the video, but I am pressing Backspace.

https://github.com/ProseMirror/prosemirror/assets/6614995/6562715d-9fbc-4cf5-a094-c992f9ecb978

Reproducible demo with code: https://glitch.com/edit/#!/candy-dazzling-spoonbill

I was able to track down the cause, it appears that the second part of this condition in readDOMChange returns a false positive, hence why the Enter event is triggered instead.

marijnh commented 2 months ago

What appears to be happening is that Firefox, for some reason, inserts a nonsense <br> node into the parent <li> item when you do this. ProseMirror then parses this, since <br> are inline content, as a newly created separate paragraph, and, since the text insertion created a new paragraph, it treats it as enter-equivalent.

Attached patch adds a kludge to detect this situation and drop the stray <br> node.