Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(sidebar): keep connection expansion stable

t8y25f19dccdc117
diff --git a/apps/desktop/src/components/sidebar/ConnectionTree.vue b/apps/desktop/src/components/sidebar/ConnectionTree.vue
index 3edea358f6..258b4bcc1c 100644
--- a/apps/desktop/src/components/sidebar/ConnectionTree.vue
+++ b/apps/desktop/src/components/sidebar/ConnectionTree.vue
@@ -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();
diff --git a/apps/desktop/src/composables/useFlatTree.ts b/apps/desktop/src/composables/useFlatTree.ts
index 20e84921f6..f1aadeffed 100644
--- a/apps/desktop/src/composables/useFlatTree.ts
+++ b/apps/desktop/src/composables/useFlatTree.ts
@@ -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;
diff --git a/packages/app-tests/useFlatTree.test.ts b/packages/app-tests/useFlatTree.test.ts
index 232933ea8c..e1e3bc8a4f 100644
--- a/packages/app-tests/useFlatTree.test.ts
+++ b/packages/app-tests/useFlatTree.test.ts
@@ -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({