mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-01-19 08:42:48 +08:00
Lexical: Aligned new empty item behaviour for nested lists
Some checks are pending
test-js / build (push) Waiting to run
Some checks are pending
test-js / build (push) Waiting to run
- 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.
This commit is contained in:
parent
ace8af077d
commit
fca8f928a3
|
@ -776,6 +776,7 @@ export function dispatchKeydownEventForNode(node: LexicalNode, editor: LexicalEd
|
|||
key,
|
||||
});
|
||||
nodeDomEl?.dispatchEvent(event);
|
||||
editor.commitUpdates();
|
||||
}
|
||||
|
||||
export function dispatchKeydownEventForSelectedNode(editor: LexicalEditor, key: string) {
|
||||
|
|
|
@ -271,11 +271,18 @@ export class ListItemNode extends ElementNode {
|
|||
insertNewAfter(
|
||||
_: RangeSelection,
|
||||
restoreSelection = true,
|
||||
): ListItemNode | ParagraphNode {
|
||||
): ListItemNode | ParagraphNode | null {
|
||||
|
||||
if (this.getTextContent().trim() === '' && this.isLastChild()) {
|
||||
const list = this.getParentOrThrow<ListNode>();
|
||||
if (!$isListItemNode(list.getParent())) {
|
||||
const parentListItem = list.getParent();
|
||||
if ($isListItemNode(parentListItem)) {
|
||||
// Un-nest list item if empty nested item
|
||||
parentListItem.insertAfter(this);
|
||||
this.selectStart();
|
||||
return null;
|
||||
} else {
|
||||
// Insert empty paragraph after list if adding after last empty child
|
||||
const paragraph = $createParagraphNode();
|
||||
list.insertAfter(paragraph, restoreSelection);
|
||||
this.remove();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -48,7 +48,6 @@ describe('Keyboard-handling service tests', () => {
|
|||
expect(lastRootChild).toBeInstanceOf(DetailsNode);
|
||||
|
||||
dispatchKeydownEventForNode(detailsPara, editor, 'ArrowDown');
|
||||
editor.commitUpdates();
|
||||
|
||||
editor.getEditorState().read(() => {
|
||||
lastRootChild = $getRoot().getLastChild();
|
||||
|
@ -79,10 +78,7 @@ describe('Keyboard-handling service tests', () => {
|
|||
expect(lastRootChild).toBeInstanceOf(DetailsNode);
|
||||
|
||||
dispatchKeydownEventForNode(detailsPara, editor, 'Enter');
|
||||
editor.commitUpdates();
|
||||
|
||||
dispatchKeydownEventForSelectedNode(editor, 'Enter');
|
||||
editor.commitUpdates();
|
||||
|
||||
let detailsChildren!: LexicalNode[];
|
||||
let lastDetailsText!: string;
|
||||
|
@ -115,7 +111,6 @@ describe('Keyboard-handling service tests', () => {
|
|||
});
|
||||
|
||||
dispatchKeydownEventForNode(listItemB, editor, 'Tab');
|
||||
editor.commitUpdates();
|
||||
|
||||
editor.getEditorState().read(() => {
|
||||
const list = $getRoot().getChildren()[0] as ListNode;
|
||||
|
|
Loading…
Reference in New Issue
Block a user