Handle bad list item children gracefully (#3226)

This commit is contained in:
Gerard Rovira
2022-10-20 02:13:35 +01:00
committed by GitHub
parent ba1274f9ee
commit d248de02b7
3 changed files with 16 additions and 9 deletions

View File

@ -369,7 +369,7 @@ export class ListItemNode extends ElementNode {
const parent = this.getParentOrThrow(); const parent = this.getParentOrThrow();
if ($isListNode(parent)) { if ($isListNode(parent)) {
const siblings = this.getNextSiblings<ListItemNode>(); const siblings = this.getNextSiblings();
updateChildrenListItemValue(parent, siblings); updateChildrenListItemValue(parent, siblings);
} }
} }

View File

@ -270,16 +270,22 @@ export function removeList(editor: LexicalEditor): void {
export function updateChildrenListItemValue( export function updateChildrenListItemValue(
list: ListNode, list: ListNode,
children?: Array<ListItemNode>, children?: Array<LexicalNode>,
): void { ): void {
(children || list.getChildren()).forEach((child: ListItemNode) => { const childrenOrExisting = children || list.getChildren();
if (childrenOrExisting !== undefined) {
for (let i = 0; i < childrenOrExisting.length; i++) {
const child = childrenOrExisting[i];
if ($isListItemNode(child)) {
const prevValue = child.getValue(); const prevValue = child.getValue();
const nextValue = $getListItemValue(child); const nextValue = $getListItemValue(child);
if (prevValue !== nextValue) { if (prevValue !== nextValue) {
child.setValue(nextValue); child.setValue(nextValue);
} }
}); }
}
}
} }
export function $handleIndent(listItemNodes: Array<ListItemNode>): void { export function $handleIndent(listItemNodes: Array<ListItemNode>): void {

View File

@ -94,5 +94,6 @@
"92": "syncChildrenFromYjs: cound not find element node", "92": "syncChildrenFromYjs: cound not find element node",
"93": "syncChildrenFromYjs: expected text, element, decorator, or linebreak collab node", "93": "syncChildrenFromYjs: expected text, element, decorator, or linebreak collab node",
"94": "splice: could not find collab element node", "94": "splice: could not find collab element node",
"95": "splice: expected offset to be greater than zero" "95": "splice: expected offset to be greater than zero",
"96": "Expected node %s to have a last child."
} }