perf(sidebar): reduce tree selection overhead
This commit is contained in:
1 parent
b4a207fc6b
commit
a2c9503a3d
5 files changed
+56
-10
No files matched your search
@@ -6,6 +6,18 @@ export function selectedTreeNodesInVisibleOrder(visibleNodes: TreeNode[], select
|
||||
return visibleNodes.filter((node) => ids.has(node.id));
|
||||
}
|
||||
|
||||
export function treeSelectionRangeIdsByIndex(
|
||||
visibleNodes: TreeNode[],
|
||||
currentIndex: number,
|
||||
anchorIndex: number,
|
||||
currentId?: string,
|
||||
): string[] {
|
||||
if (anchorIndex < 0 || currentIndex < 0) return currentId ? [currentId] : [];
|
||||
const start = Math.min(anchorIndex, currentIndex);
|
||||
const end = Math.max(anchorIndex, currentIndex);
|
||||
return visibleNodes.slice(start, end + 1).map((node) => node.id);
|
||||
}
|
||||
|
||||
export function treeSelectionRangeIds(
|
||||
visibleNodes: TreeNode[],
|
||||
currentId: string,
|
||||
@@ -15,8 +27,5 @@ export function treeSelectionRangeIds(
|
||||
const anchor = anchorId || selectedId || currentId;
|
||||
const anchorIndex = visibleNodes.findIndex((node) => node.id === anchor);
|
||||
const currentIndex = visibleNodes.findIndex((node) => node.id === currentId);
|
||||
if (anchorIndex < 0 || currentIndex < 0) return [currentId];
|
||||
const start = Math.min(anchorIndex, currentIndex);
|
||||
const end = Math.max(anchorIndex, currentIndex);
|
||||
return visibleNodes.slice(start, end + 1).map((node) => node.id);
|
||||
return treeSelectionRangeIdsByIndex(visibleNodes, currentIndex, anchorIndex, currentId);
|
||||
}
|
||||
Reference in new issue
Block a user