Skip to content

Commit

Permalink
Merge branch 'main' into indent-html
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum authored Oct 6, 2024
2 parents 4de37a7 + d273333 commit 2f4e12d
Show file tree
Hide file tree
Showing 8 changed files with 484 additions and 38 deletions.
18 changes: 10 additions & 8 deletions packages/lexical-list/src/formatList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,36 +157,38 @@ function $createListOrMerge(node: ElementNode, listType: ListType): ListNode {
const previousSibling = node.getPreviousSibling();
const nextSibling = node.getNextSibling();
const listItem = $createListItemNode();
listItem.setFormat(node.getFormatType());
listItem.setIndent(node.getIndent());
append(listItem, node.getChildren());

let targetList;
if (
$isListNode(previousSibling) &&
listType === previousSibling.getListType()
) {
previousSibling.append(listItem);
node.remove();
// if the same type of list is on both sides, merge them.

if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
append(previousSibling, nextSibling.getChildren());
nextSibling.remove();
}
return previousSibling;
targetList = previousSibling;
} else if (
$isListNode(nextSibling) &&
listType === nextSibling.getListType()
) {
nextSibling.getFirstChildOrThrow().insertBefore(listItem);
node.remove();
return nextSibling;
targetList = nextSibling;
} else {
const list = $createListNode(listType);
list.append(listItem);
node.replace(list);
return list;
targetList = list;
}
// listItem needs to be attached to root prior to setting indent
listItem.setFormat(node.getFormatType());
listItem.setIndent(node.getIndent());
node.remove();

return targetList;
}

/**
Expand Down
Loading

0 comments on commit 2f4e12d

Please sign in to comment.