mirror of
https://github.com/facebook/lexical.git
synced 2025-05-17 15:18:47 +08:00
Handle bad list item children gracefully (#3226)
This commit is contained in:
@ -369,7 +369,7 @@ export class ListItemNode extends ElementNode {
|
||||
const parent = this.getParentOrThrow();
|
||||
|
||||
if ($isListNode(parent)) {
|
||||
const siblings = this.getNextSiblings<ListItemNode>();
|
||||
const siblings = this.getNextSiblings();
|
||||
updateChildrenListItemValue(parent, siblings);
|
||||
}
|
||||
}
|
||||
|
@ -270,16 +270,22 @@ export function removeList(editor: LexicalEditor): void {
|
||||
|
||||
export function updateChildrenListItemValue(
|
||||
list: ListNode,
|
||||
children?: Array<ListItemNode>,
|
||||
children?: Array<LexicalNode>,
|
||||
): void {
|
||||
(children || list.getChildren()).forEach((child: ListItemNode) => {
|
||||
const prevValue = child.getValue();
|
||||
const nextValue = $getListItemValue(child);
|
||||
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 nextValue = $getListItemValue(child);
|
||||
|
||||
if (prevValue !== nextValue) {
|
||||
child.setValue(nextValue);
|
||||
if (prevValue !== nextValue) {
|
||||
child.setValue(nextValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function $handleIndent(listItemNodes: Array<ListItemNode>): void {
|
||||
|
@ -94,5 +94,6 @@
|
||||
"92": "syncChildrenFromYjs: cound not find element node",
|
||||
"93": "syncChildrenFromYjs: expected text, element, decorator, or linebreak collab 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."
|
||||
}
|
||||
|
Reference in New Issue
Block a user