Skip to content

Commit fca8f92

Browse files
committed
Lexical: Aligned new empty item behaviour for nested lists
- Makes enter on empty nested list item un-nest instead of just creating new list items. - Also updated existing lists tests to use newer helper setup.
1 parent ace8af0 commit fca8f92

File tree

4 files changed

+538
-520
lines changed

4 files changed

+538
-520
lines changed

resources/js/wysiwyg/lexical/core/__tests__/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ export function dispatchKeydownEventForNode(node: LexicalNode, editor: LexicalEd
776776
key,
777777
});
778778
nodeDomEl?.dispatchEvent(event);
779+
editor.commitUpdates();
779780
}
780781

781782
export function dispatchKeydownEventForSelectedNode(editor: LexicalEditor, key: string) {

resources/js/wysiwyg/lexical/list/LexicalListItemNode.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,18 @@ export class ListItemNode extends ElementNode {
271271
insertNewAfter(
272272
_: RangeSelection,
273273
restoreSelection = true,
274-
): ListItemNode | ParagraphNode {
274+
): ListItemNode | ParagraphNode | null {
275275

276276
if (this.getTextContent().trim() === '' && this.isLastChild()) {
277277
const list = this.getParentOrThrow<ListNode>();
278-
if (!$isListItemNode(list.getParent())) {
278+
const parentListItem = list.getParent();
279+
if ($isListItemNode(parentListItem)) {
280+
// Un-nest list item if empty nested item
281+
parentListItem.insertAfter(this);
282+
this.selectStart();
283+
return null;
284+
} else {
285+
// Insert empty paragraph after list if adding after last empty child
279286
const paragraph = $createParagraphNode();
280287
list.insertAfter(paragraph, restoreSelection);
281288
this.remove();

0 commit comments

Comments
 (0)