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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
feat(sidebar): add locate-in-sidebar button to find active tab's node
t8y20c806be274e6
diff --git a/apps/desktop/src/components/sidebar/ConnectionTree.vue b/apps/desktop/src/components/sidebar/ConnectionTree.vueindex fad38199a6..81f33c6ef9 100644--- a/apps/desktop/src/components/sidebar/ConnectionTree.vue+++ b/apps/desktop/src/components/sidebar/ConnectionTree.vue@@ -6,6 +6,7 @@ import {X,ListFilter,FolderPlus,+ Crosshair,Server,Database,FolderTree,@@ -16,11 +17,13 @@ import {import { useConnectionStore } from "@/stores/connectionStore";import { useQueryStore } from "@/stores/queryStore";import { useSettingsStore } from "@/stores/settingsStore";-import type { TreeNode, TreeNodeType } from "@/types/database";+import type { QueryTab, TreeNode, TreeNodeType } from "@/types/database";import { filterSidebarTree } from "@/lib/sidebarSearchTree";import { isCancelSearchShortcut } from "@/lib/keyboardShortcuts";+import { usesTreeSchemaMode } from "@/lib/databaseFeatureSupport";import {findSidebarNodeForActiveTab,+ findNodePathForActiveTab,scrollTopForSidebarNode,shouldScrollActiveSidebarSelection,} from "@/lib/sidebarActiveTabTarget";@@ -162,6 +165,8 @@ const useVirtualTree = computed(() => shouldVirtualizeFlatTree(flatNodes.value.lconst activeTab = computed(() => queryStore.tabs.find((tab) => tab.id === queryStore.activeTabId));const pendingRenameGroupId = ref<string | null>(null);+const highlightedNodeId = ref<string | null>(null);+let highlightTimer: number | undefined;async function scrollToSidebarNode(nodeId: string) {await nextTick();@@ -195,6 +200,135 @@ async function createNewGroup() {store.selectedTreeNodeId = groupId;}+async function locateActiveTabInSidebar() {+ const tab = activeTab.value;+ if (!tab) return;++ const connId = tab.connectionId;++ // Reconnect if the connection was disconnected (children are cleared on disconnect)+ if (connId && !store.connectedIds.has(connId)) {+ const config = store.getConfig(connId);+ if (!config) return;+ try {+ await store.connect(config);+ } catch {+ return;+ }+ }++ // Ensure the tree is loaded deep enough to contain the target node+ await ensureTreeLoadedForTab(tab);++ // Clear any active search filter so the node is visible+ if (isFiltering.value) {+ searchQuery.value = "";+ deferredSearchQuery.value = "";+ clearSearchScopeFilter();+ }++ const nodePath = findNodePathForActiveTab(tab, store.treeNodes);+ if (!nodePath) return;++ for (const ancestor of nodePath) {+ if (!ancestor.isExpanded) {+ ancestor.isExpanded = true;+ }+ }++ await nextTick();++ const match = findSidebarNodeForActiveTab(tab, flatNodes.value);+ if (!match) return;++ store.selectedTreeNodeId = match.id;+ await nextTick();++ window.clearTimeout(highlightTimer);+ highlightedNodeId.value = match.id;+ highlightTimer = window.setTimeout(() => {+ highlightedNodeId.value = null;+ }, 1800);++ await scrollToSidebarNode(match.id);+}++async function ensureTreeLoadedForTab(tab: QueryTab) {+ const connId = tab.connectionId;+ if (!connId) return;++ const config = store.getConfig(connId);+ if (!config) return;++ // Ensure databases are loaded under the connection+ const connNode = store.treeNodes.find((n) => n.id === connId);+ if (connNode && (!connNode.children || connNode.children.length === 0)) {+ try {+ if (config.db_type === "redis") {+ await store.loadRedisDatabases(connId);+ } else if (config.db_type === "mongodb" || config.db_type === "elasticsearch") {+ await store.loadMongoDatabases(connId);+ } else {+ await store.loadDatabases(connId);+ }+ } catch {+ return;+ }+ }++ if (!tab.database) return;++ // Find the database node+ const dbNode = findDatabaseNode(store.treeNodes, connId, tab.database);+ if (!dbNode || (dbNode.children && dbNode.children.length > 0)) return;++ // Load database contents+ try {+ if (config.db_type === "sqlserver") {+ await store.loadSqlServerDatabaseObjects(connId, tab.database);+ } else if (usesTreeSchemaMode(config.db_type)) {+ await store.loadSchemas(connId, tab.database);+ // If we have a schema, also load tables under that schema+ if (tab.schema) {+ const schemaNode = findSchemaNode(store.treeNodes, connId, tab.database, tab.schema);+ if (schemaNode && (!schemaNode.children || schemaNode.children.length === 0)) {+ await store.loadTables(connId, tab.database, tab.schema);+ }+ }+ } else {+ await store.loadTables(connId, tab.database);+ }+ } catch {+ // Node just won't have children loaded+ }+}++function findDatabaseNode(nodes: TreeNode[], connId: string, database: string): TreeNode | null {+ for (const node of nodes) {+ if (node.type === "database" && node.connectionId === connId && node.database === database) {+ return node;+ }+ if (node.children) {+ const found = findDatabaseNode(node.children, connId, database);+ if (found) return found;+ }+ }+ return null;+}++function findSchemaNode(nodes: TreeNode[], connId: string, database: string, schema: string): TreeNode | null {+ for (const node of nodes) {+ if (node.type === "schema" && node.connectionId === connId && node.database === database && node.label === schema) {+ return node;+ }+ if (node.children) {+ const found = findSchemaNode(node.children, connId, database, schema);+ if (found) return found;+ }+ }+ return null;+}+function onSearchToggle(node: TreeNode) {if (!isSearching.value || !node.children) return;const next = new Set(searchCollapsedIds.value);@@ -313,6 +447,13 @@ defineExpose({ focusSearch });<X class="h-3 w-3" /></button></div>+ <button+ class="shrink-0 h-6 w-6 flex items-center justify-center rounded border border-border text-muted-foreground hover:bg-accent hover:text-foreground"+ :title="t('sidebar.locateActiveTab')"+ @click="locateActiveTabInSidebar"+ >+ <Crosshair class="h-3.5 w-3.5" />+ </button><buttonclass="shrink-0 h-6 w-6 flex items-center justify-center rounded border border-border text-muted-foreground hover:bg-accent hover:text-foreground":title="t('connectionGroup.createGroup')"@@ -367,6 +508,7 @@ defineExpose({ focusSearch });:depth="item.depth":drag-disabled="isFiltering":pending-rename="pendingRenameGroupId === item.node.id"+ :highlighted="highlightedNodeId === item.node.id"@node-toggled="onNodeToggled"@search-toggle="onSearchToggle"@rename-started="pendingRenameGroupId = null"@@ -385,6 +527,7 @@ defineExpose({ focusSearch });:depth="item.depth":drag-disabled="isFiltering":pending-rename="pendingRenameGroupId === item.node.id"+ :highlighted="highlightedNodeId === item.id"@node-toggled="onNodeToggled"@search-toggle="onSearchToggle"@rename-started="pendingRenameGroupId = null"diff --git a/apps/desktop/src/components/sidebar/TreeItem.vue b/apps/desktop/src/components/sidebar/TreeItem.vueindex a5774e74ff..843b918c34 100644--- a/apps/desktop/src/components/sidebar/TreeItem.vue+++ b/apps/desktop/src/components/sidebar/TreeItem.vue@@ -145,6 +145,7 @@ const props = defineProps<{depth: number;dragDisabled?: boolean;pendingRename?: boolean;+ highlighted?: boolean;}>();const emit = defineEmits<{@@ -2245,6 +2246,7 @@ function treeItemMenuItems(): ContextMenuItem[] {'rounded-none': connectionColor && !isSelected,'rounded-sm': !connectionColor && !isSelected,'tree-item-active rounded-md': isSelected,+ 'tree-item-highlight': highlighted,}":tabindex="isSelected ? 0 : -1":style="rowStyle"@@ -2662,4 +2664,15 @@ function treeItemMenuItems(): ContextMenuItem[] {:root.dark .tree-item-active:focus {background-color: oklch(0.35 0.06 250) !important;}++/* Locate highlight: instant amber, then fade on removal */+.tree-item-highlight {+ background-color: oklch(0.92 0.08 85) !important;+ transition: background-color 0.8s ease-out 0.6s;+}++:root.dark .tree-item-highlight {+ background-color: oklch(0.42 0.12 80) !important;+ transition: background-color 0.8s ease-out 0.6s;+}</style>diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.tsindex f01355b8da..c773490e20 100644--- a/apps/desktop/src/i18n/locales/en.ts+++ b/apps/desktop/src/i18n/locales/en.ts@@ -80,6 +80,7 @@ export default {searchScopeTable: "Table",searchScopeView: "View",clearFilter: "Clear filter",+ locateActiveTab: "Locate in sidebar",},savedSql: {saveToLibrary: "Save to SQL Library",diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.tsindex 9e4140065f..66b074e0ca 100644--- a/apps/desktop/src/i18n/locales/es.ts+++ b/apps/desktop/src/i18n/locales/es.ts@@ -80,6 +80,7 @@ export default {searchScopeTable: "Tabla",searchScopeView: "Vista",clearFilter: "Limpiar filtro",+ locateActiveTab: "Localizar en la barra lateral",},savedSql: {saveToLibrary: "Guardar en biblioteca SQL",diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.tsindex cd9cdaf210..e88183cbc5 100644--- a/apps/desktop/src/i18n/locales/zh-CN.ts+++ b/apps/desktop/src/i18n/locales/zh-CN.ts@@ -79,6 +79,7 @@ export default {searchScopeTable: "表",searchScopeView: "视图",clearFilter: "清除筛选",+ locateActiveTab: "在侧边栏中定位",},savedSql: {saveToLibrary: "保存到 SQL 库",diff --git a/apps/desktop/src/lib/sidebarActiveTabTarget.ts b/apps/desktop/src/lib/sidebarActiveTabTarget.tsindex 49c074955d..b40b2ef606 100644--- a/apps/desktop/src/lib/sidebarActiveTabTarget.ts+++ b/apps/desktop/src/lib/sidebarActiveTabTarget.ts@@ -18,6 +18,12 @@ export type ActiveTabSidebarTarget =| {type: "saved-sql-file";savedSqlId: string;+ }+ | {+ type: "query-context";+ connectionId: string;+ database: string;+ schema?: string;};export function activeTabSidebarTarget(tab: QueryTab | undefined | null): ActiveTabSidebarTarget | null {@@ -50,6 +56,16 @@ export function activeTabSidebarTarget(tab: QueryTab | undefined | null): Active};}+ if (tab.mode === "query") {+ if (!tab.connectionId || !tab.database) return null;+ return {+ type: "query-context",+ connectionId: tab.connectionId,+ database: tab.database,+ schema: tab.schema,+ };+ }+return null;}@@ -58,7 +74,7 @@ function schemaMatches(node: TreeNode, schema: string | undefined): boolean {return (node.schema || "") === schema;}-function matchesTarget(node: TreeNode, target: ActiveTabSidebarTarget): boolean {+export function matchesTarget(node: TreeNode, target: ActiveTabSidebarTarget): boolean {if (target.type === "saved-sql-file") {return node.type === "saved-sql-file" && node.savedSqlId === target.savedSqlId;}@@ -72,6 +88,18 @@ function matchesTarget(node: TreeNode, target: ActiveTabSidebarTarget): boolean);}+ if (target.type === "query-context") {+ if (target.schema) {+ return (+ node.type === "schema" &&+ node.connectionId === target.connectionId &&+ node.database === target.database &&+ node.label === target.schema+ );+ }+ return node.type === "database" && node.connectionId === target.connectionId && node.label === target.database;+ }+return ((node.type === "table" || node.type === "view") &&node.connectionId === target.connectionId &&@@ -121,3 +149,28 @@ export function scrollTopForSidebarNode(options: {if (rowBottom > viewportBottom) return Math.max(0, rowBottom - options.viewportHeight);return options.currentScrollTop;}++export function findNodePathForActiveTab(+ tab: QueryTab | undefined | null,+ treeNodes: readonly TreeNode[],+): TreeNode[] | null {+ const target = activeTabSidebarTarget(tab);+ if (!target) return null;+ return findPath(treeNodes, (node) => matchesTarget(node, target));+}++function findPath(+ nodes: readonly TreeNode[],+ predicate: (node: TreeNode) => boolean,+ path: TreeNode[] = [],+): TreeNode[] | null {+ for (const node of nodes) {+ const currentPath = [...path, node];+ if (predicate(node)) return currentPath;+ if (node.children) {+ const result = findPath(node.children, predicate, currentPath);+ if (result) return result;+ }+ }+ return null;+}