chore: ensures that de-indenting top-level lists works in all cases

This commit is contained in:
James
2022-12-23 13:11:38 -05:00
parent 794b6e8783
commit 55df622007

View File

@@ -65,18 +65,26 @@ const indent = {
},
});
// Lift the nested lis
Transforms.liftNodes(editor, {
at: parentListItemPath,
match: (node, path) => {
const matches = !Editor.isEditor(node)
&& Element.isElement(node)
&& path.length === parentListItemPath.length + 1
&& node.type === 'li';
// Parent list item path has changed at this point
// so we need to re-fetch the parent node
const [newParentNode] = Editor.node(editor, parentListItemPath);
return matches;
},
});
// If the parent node is an li,
// lift all li nodes within
if (Element.isElement(newParentNode) && newParentNode.type === 'li') {
// Lift the nested lis
Transforms.liftNodes(editor, {
at: parentListItemPath,
match: (node, path) => {
const matches = !Editor.isEditor(node)
&& Element.isElement(node)
&& path.length === parentListItemPath.length + 1
&& node.type === 'li';
return matches;
},
});
}
} else {
Transforms.unwrapNodes(editor, {
at: parentListItemPath,
@@ -94,6 +102,12 @@ const indent = {
} else {
unwrapList(editor, listPath);
}
} else {
Transforms.unwrapNodes(editor, {
match: (n) => Element.isElement(n) && n.type === indentType,
split: true,
mode: 'lowest',
});
}
}