Fix insertText bug (#1197)

* Fix insertText bug

* Update codes
This commit is contained in:
Dominic Gannaway
2022-01-28 23:25:23 +00:00
committed by acywatson
parent ed43e133dc
commit b2f73f34e8
3 changed files with 8 additions and 2 deletions

View File

@ -557,7 +557,7 @@ export class Selection {
// If the last element is an "inline" element, don't move it's text nodes to the first node. // If the last element is an "inline" element, don't move it's text nodes to the first node.
// Instead, preserve the "inline" element's children and append to the first element. // Instead, preserve the "inline" element's children and append to the first element.
if (!lastElement.canBeEmpty()) { if (!lastElement.canBeEmpty() && firstElement !== lastElement) {
firstElement.append(lastElement); firstElement.append(lastElement);
} else { } else {
for (let i = lastNodeChildren.length - 1; i >= 0; i--) { for (let i = lastNodeChildren.length - 1; i >= 0; i--) {

View File

@ -260,6 +260,9 @@ export class ElementNode extends LexicalNode {
} }
for (let i = 0; i < nodesToAppendLength; i++) { for (let i = 0; i < nodesToAppendLength; i++) {
const nodeToAppend = nodesToAppend[i]; const nodeToAppend = nodesToAppend[i];
if (nodeToAppend.__key === writableSelfKey) {
invariant(false, 'append: attemtping to append self');
}
const writableNodeToAppend = nodeToAppend.getWritable(); const writableNodeToAppend = nodeToAppend.getWritable();
// Remove node from previous parent // Remove node from previous parent

View File

@ -45,5 +45,8 @@
"43": "reconcileNode: prevNode or nextNode does not exist in nodeMap", "43": "reconcileNode: prevNode or nextNode does not exist in nodeMap",
"44": "reconcileNode: parentDOM is null", "44": "reconcileNode: parentDOM is null",
"45": "Reconciliation: could not find DOM element for node key \"${key}\"", "45": "Reconciliation: could not find DOM element for node key \"${key}\"",
"46": "rootNode.append: Only element or decorator nodes can be appended to the root node" "46": "rootNode.append: Only element or decorator nodes can be appended to the root node",
"47": "getListItemValue: list node is not parent of list item node",
"48": "Should never happen",
"49": "append: attemtping to append self"
} }