Skip to content

Commit

Permalink
make condition mutually exclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara committed Jan 16, 2025
1 parent 30fd91b commit 5b67c8e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
25 changes: 24 additions & 1 deletion packages/lexical-list/src/__tests__/unit/formatList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
TableNode,
TableRowNode,
} from '@lexical/table';
import {$getRoot} from 'lexical';
import {$createParagraphNode, $createTextNode, $getRoot} from 'lexical';
import {initializeUnitTest} from 'lexical/src/__tests__/utils';

import {insertList} from '../../formatList';

Check failure on line 20 in packages/lexical-list/src/__tests__/unit/formatList.test.ts

View workflow job for this annotation

GitHub Actions / core-tests / integrity (20.11.0)

'"../../formatList"' has no exported member named 'insertList'. Did you mean '$insertList'?
Expand Down Expand Up @@ -42,6 +42,29 @@ describe('insertList', () => {
});
});

test('inserting in root selection with existing child', async () => {
const {editor} = testEnv;

await editor.update(() => {
$getRoot().select();
$getRoot().append(
$createParagraphNode().append($createTextNode('hello')),
);
});

insertList(editor, 'number');

editor.read(() => {
const root = $getRoot();

expect(root.getChildrenSize()).toBe(1);

const firstChild = root.getFirstChildOrThrow();

expect($isListNode(firstChild)).toBe(true);
});
});

test('inserting with empty shadow root selection', async () => {
const {editor} = testEnv;

Expand Down
4 changes: 1 addition & 3 deletions packages/lexical-list/src/formatList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ export function $insertList(listType: ListType): void {
anchorNode.append(paragraph);
nodes = paragraph.select().getNodes();
}
}

if ($isSelectingEmptyListItem(anchorNode, nodes)) {
} else if ($isSelectingEmptyListItem(anchorNode, nodes)) {
const list = $createListNode(listType);

if ($isRootOrShadowRoot(anchorNodeParent)) {
Expand Down

0 comments on commit 5b67c8e

Please sign in to comment.