mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-31 15:24:31 +03:00
Lexical: Made list selections & intendting more reliable
- Added handling to not include parent of top-most list range selection so that it's not also changed while not visually part of the selection range. - Fixed issue where list items could be left over after unnesting, due to empty checks/removals occuring before all child handling. - Added node sorting, applied to list items during nest operations so that selection range remains reliable.
This commit is contained in:
@ -94,6 +94,30 @@ export function $getNearestNodeBlockParent(node: LexicalNode): LexicalNode|null
|
||||
return $findMatchingParent(node, isBlockNode);
|
||||
}
|
||||
|
||||
export function $sortNodes(nodes: LexicalNode[]): LexicalNode[] {
|
||||
const idChain: string[] = [];
|
||||
const addIds = (n: ElementNode) => {
|
||||
for (const child of n.getChildren()) {
|
||||
idChain.push(child.getKey())
|
||||
if ($isElementNode(child)) {
|
||||
addIds(child)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const root = $getRoot();
|
||||
addIds(root);
|
||||
|
||||
const sorted = Array.from(nodes);
|
||||
sorted.sort((a, b) => {
|
||||
const aIndex = idChain.indexOf(a.getKey());
|
||||
const bIndex = idChain.indexOf(b.getKey());
|
||||
return aIndex - bIndex;
|
||||
});
|
||||
|
||||
return sorted;
|
||||
}
|
||||
|
||||
export function nodeHasAlignment(node: object): node is NodeHasAlignment {
|
||||
return '__alignment' in node;
|
||||
}
|
||||
|
Reference in New Issue
Block a user