The v2-html-paste path was broken since it was introduced. The paste
handler called the formatted/plain dispatcher without the selection
controller, so reading `clipboardData.types` threw on every paste while
the feature was enabled. The HTML branch also never forwarded the
allowHTMLPaste flag to mapContentFragmentFromHTML, and that function
called mapContentFragmentFromDocument() without the root node, so
createNodeIterator() threw and the silent fallback always degraded the
paste to plain text.
Pass the selection controller through the dispatcher, forward the flag
from the formatted fragment helper, and iterate the parsed document from
its body.
AI-assisted-by: longcat-2.0-free
Pasting text could throw "Unknown node type" and lose the paste. The
insertion paths assume the caret sits on a text node or a <br>, but the
browser can report it on a container element (the offset being a child
index, common in Firefox) or, for an empty text shape that was just
focused, on nothing at all: selectAll() returned early without ever
setting a selection.
Add resolveTextNodePosition(), which walks a (node, offset) pair down to
the addressed text node or line break and returns null instead of
throwing when it cannot. The selection controller normalizes the caret
with it before inserting text or a pasted fragment, and selectAll() now
collapses on the line break of an empty editor so the caret is always
usable.
Closes#11149
AI-assisted-by: longcat-2.0-free
The text editor's SelectionController threw 'TypeError: Invalid text
node' when:
- Pressing Backspace to delete the only character of the **first** text
span in a paragraph that contains multiple spans.
- Pressing Delete to delete the only character of the **last** text
span in the same situation.
- Pressing a word-backward shortcut that empties the first span of a
multi-span paragraph.
In all three cases the tree-iterator (previousNode / nextNode) returned
null because no sibling text node existed in that direction, and that
null was subsequently passed to getTextNodeLength() which calls
isTextNode() — which unconditionally throws when given a falsy value.
Fix: use the null-coalescing fallback to the first/last remaining
child's text node of the paragraph before calling collapse() /
getTextNodeLength().