1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Lexical: Improved list tab handling, Improved test utils

- Made tab work on empty list items
- Improved select preservation on single list item tab
- Altered test context creation for more standard testing
This commit is contained in:
Dan Brown
2024-12-17 14:44:10 +00:00
parent e50cd33277
commit ace8af077d
4 changed files with 154 additions and 70 deletions

View File

@ -151,6 +151,15 @@ function getDetailsScenario(editor: LexicalEditor): {
}
}
function $isSingleListItem(nodes: LexicalNode[]): boolean {
if (nodes.length !== 1) {
return false;
}
const node = nodes[0];
return $isListItemNode(node) || $isListItemNode(node.getParent());
}
/**
* Inset the nodes within selection when a range of nodes is selected
* or if a list node is selected.
@ -159,7 +168,7 @@ function handleInsetOnTab(editor: LexicalEditor, event: KeyboardEvent|null): boo
const change = event?.shiftKey ? -40 : 40;
const selection = $getSelection();
const nodes = selection?.getNodes() || [];
if (nodes.length > 1 || (nodes.length === 1 && $isListItemNode(nodes[0].getParent()))) {
if (nodes.length > 1 || $isSingleListItem(nodes)) {
editor.update(() => {
$setInsetForSelection(editor, change);
});