fix(sidebar): reveal expanded tree items

This commit is contained in:
t8y2
2026-05-18 16:35:09 +08:00
parent 28f4aec50d
commit ab87de4054
4 changed files with 83 additions and 1 deletions
+25
View File
@@ -5,6 +5,7 @@ import {
SIDEBAR_TREE_PRERENDER_COUNT,
SIDEBAR_TREE_SCROLL_BUFFER,
flattenTree,
scrollTopForExpandedTreeNode,
shouldVirtualizeFlatTree,
} from "../../apps/desktop/src/composables/useFlatTree.ts";
import type { TreeNode } from "../../apps/desktop/src/types/database.ts";
@@ -57,3 +58,27 @@ test("sidebar virtual tree keeps enough buffered rows for fast scrolling", () =>
test("sidebar virtual tree prerenders enough rows for the first frame", () => {
assert.ok(SIDEBAR_TREE_PRERENDER_COUNT >= 40);
});
test("expanded sidebar nodes scroll enough to reveal inserted rows", () => {
assert.equal(
scrollTopForExpandedTreeNode({
expandedIndex: 20,
insertedRowCount: 2,
currentScrollTop: 15 * SIDEBAR_TREE_ROW_HEIGHT,
viewportHeight: 6 * SIDEBAR_TREE_ROW_HEIGHT,
}),
17 * SIDEBAR_TREE_ROW_HEIGHT,
);
});
test("expanded sidebar nodes keep scroll position when children are already visible", () => {
assert.equal(
scrollTopForExpandedTreeNode({
expandedIndex: 4,
insertedRowCount: 2,
currentScrollTop: 0,
viewportHeight: 8 * SIDEBAR_TREE_ROW_HEIGHT,
}),
0,
);
});