fix(sidebar): keep connection expansion stable
This commit is contained in:
parent
7a3ff3bff9
commit
5f19dccdc1
|
|
@ -15,6 +15,7 @@ import {
|
|||
SIDEBAR_TREE_SCROLL_BUFFER,
|
||||
flattenTree,
|
||||
scrollTopForExpandedTreeNode,
|
||||
shouldAutoScrollExpandedTreeNode,
|
||||
shouldVirtualizeFlatTree,
|
||||
type FlatTreeNode,
|
||||
} from "@/composables/useFlatTree";
|
||||
|
|
@ -144,6 +145,7 @@ function onSearchToggle(node: TreeNode) {
|
|||
|
||||
async function onNodeToggled(node: TreeNode, wasExpanded: boolean) {
|
||||
if (wasExpanded || !node.isExpanded) return;
|
||||
if (!shouldAutoScrollExpandedTreeNode(node.type)) return;
|
||||
|
||||
await nextTick();
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,10 @@ export function shouldVirtualizeFlatTree(count: number): boolean {
|
|||
return count > 0;
|
||||
}
|
||||
|
||||
export function shouldAutoScrollExpandedTreeNode(type: TreeNodeType): boolean {
|
||||
return type !== "connection" && type !== "connection-group";
|
||||
}
|
||||
|
||||
export function scrollTopForExpandedTreeNode(options: {
|
||||
expandedIndex: number;
|
||||
insertedRowCount: number;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
SIDEBAR_TREE_SCROLL_BUFFER,
|
||||
flattenTree,
|
||||
scrollTopForExpandedTreeNode,
|
||||
shouldAutoScrollExpandedTreeNode,
|
||||
shouldVirtualizeFlatTree,
|
||||
} from "../../apps/desktop/src/composables/useFlatTree.ts";
|
||||
import type { TreeNode } from "../../apps/desktop/src/types/database.ts";
|
||||
|
|
@ -59,6 +60,13 @@ test("sidebar virtual tree prerenders enough rows for the first frame", () => {
|
|||
assert.ok(SIDEBAR_TREE_PRERENDER_COUNT >= 40);
|
||||
});
|
||||
|
||||
test("sidebar keeps root connection expansion from changing scroll position", () => {
|
||||
assert.equal(shouldAutoScrollExpandedTreeNode("connection"), false);
|
||||
assert.equal(shouldAutoScrollExpandedTreeNode("connection-group"), false);
|
||||
assert.equal(shouldAutoScrollExpandedTreeNode("database"), true);
|
||||
assert.equal(shouldAutoScrollExpandedTreeNode("group-columns"), true);
|
||||
});
|
||||
|
||||
test("expanded sidebar nodes scroll enough to reveal inserted rows", () => {
|
||||
assert.equal(
|
||||
scrollTopForExpandedTreeNode({
|
||||
|
|
|
|||
Loading…
Reference in New Issue