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): open the first search match with Enter
弈秋739e805b83d3
diff --git a/apps/desktop/src/components/sidebar/ConnectionTree.vue b/apps/desktop/src/components/sidebar/ConnectionTree.vueindex 6117beeeb7..0193d10f0a 100644--- a/apps/desktop/src/components/sidebar/ConnectionTree.vue+++ b/apps/desktop/src/components/sidebar/ConnectionTree.vue@@ -26,6 +26,7 @@ import {localTableSearchParentTypes,} from "@/lib/sidebar/sidebarSearchTree";import { createSidebarLabelMatcher } from "@/lib/sidebar/sidebarSearch";+import { firstSidebarSearchMatchDataNode, hasActiveSidebarSearch } from "@/lib/sidebar/sidebarSearchEnter";import { collectSidebarRegexIndexScopes, resolveSidebarRemoteSearchQuery, resolveSidebarSearchDispatchMode, shouldRestoreTrackedSidebarSearchTargetsInRegexMode } from "@/lib/sidebar/sidebarRegexSearchIndex";import { needsSidebarObjectGroupDiscovery } from "@/lib/sidebar/sidebarSearchDiscovery";import { isSidebarSearchPrunedDatabaseNode, resolveSidebarSearchDatabaseScope } from "@/lib/sidebar/sidebarSearchDatabaseScope";@@ -2435,6 +2436,14 @@ function focusSearch(target: Element | null = null): boolean {}function onSearchKeydown(event: KeyboardEvent) {+ if (event.key === "Enter" && !event.isComposing && !event.defaultPrevented) {+ const node = firstSidebarSearchMatchDataNode(visibleNodes.value, hasActiveSidebarSearch(searchQuery.value, store.sidebarTableSearchQueries));+ if (node) {+ event.preventDefault();+ sidebarTreeRuntimeHostRef.value?.handleRowClick(node, 1);+ }+ return;+ }if (!isCancelSearchShortcut(event)) return;event.preventDefault();searchQuery.value = "";diff --git a/apps/desktop/src/lib/__tests__/sidebar/sidebarSearchEnter.spec.ts b/apps/desktop/src/lib/__tests__/sidebar/sidebarSearchEnter.spec.tsnew file mode 100644index 0000000000..46ddfb7e3d--- /dev/null+++ b/apps/desktop/src/lib/__tests__/sidebar/sidebarSearchEnter.spec.ts@@ -0,0 +1,40 @@+import { describe, expect, it } from "vitest";+import { firstSidebarSearchMatchDataNode, hasActiveSidebarSearch } from "@/lib/sidebar/sidebarSearchEnter";+import type { TreeNode } from "@/types/database";++function node(id: string, type: TreeNode["type"]): TreeNode {+ return {+ id,+ type,+ label: id,+ connectionId: "conn",+ database: "app",+ children: [],+ isExpanded: false,+ } as TreeNode;+}++describe("sidebar search Enter-to-open", () => {+ it("opens the first visible table-like node in tree order", () => {+ const nodes = [node("schema", "schema"), node("users", "table"), node("orders", "view"), node("billing", "materialized_view")];+ expect(firstSidebarSearchMatchDataNode(nodes, true)?.id).toBe("users");+ });++ it("returns null without table-like rows even when searching", () => {+ const nodes = [node("conn", "connection"), node("app", "database"), node("schema", "schema")];+ expect(firstSidebarSearchMatchDataNode(nodes, true)).toBeNull();+ expect(firstSidebarSearchMatchDataNode([], true)).toBeNull();+ });++ it("ignores the visible tree when no search is active", () => {+ const nodes = [node("users", "table")];+ expect(firstSidebarSearchMatchDataNode(nodes, false)).toBeNull();+ });++ it("treats the global query and per-database table searches as active search surfaces", () => {+ expect(hasActiveSidebarSearch(" users ", {})).toBe(true);+ expect(hasActiveSidebarSearch("", { "conn:app": "users" })).toBe(true);+ expect(hasActiveSidebarSearch("", {})).toBe(false);+ expect(hasActiveSidebarSearch(" ", { "conn:app": " " })).toBe(false);+ });+});diff --git a/apps/desktop/src/lib/sidebar/sidebarSearchEnter.ts b/apps/desktop/src/lib/sidebar/sidebarSearchEnter.tsnew file mode 100644index 0000000000..859ced8645--- /dev/null+++ b/apps/desktop/src/lib/sidebar/sidebarSearchEnter.ts@@ -0,0 +1,23 @@+import type { TreeNode, TreeNodeType } from "@/types/database";++// Row types whose single-click action opens the object's data. Pressing Enter+// in the sidebar search opens the first matching one of these.+const sidebarSearchOpenFirstNodeTypes = new Set<TreeNodeType>(["table", "view", "materialized_view"]);++/** True when any sidebar search surface (global query or per-database table search) is active. */+export function hasActiveSidebarSearch(globalQuery: string, tableSearchQueries: Readonly<Record<string, string>>): boolean {+ if (globalQuery.trim().length > 0) return true;+ return Object.values(tableSearchQueries).some((query) => query.trim().length > 0);+}++/**+ * The first visible data node a search should open on Enter, in tree display+ * order. Returns null when no table-like row is visible.+ */+export function firstSidebarSearchMatchDataNode(nodes: readonly TreeNode[], hasActiveSearch: boolean): TreeNode | null {+ if (!hasActiveSearch) return null;+ for (const node of nodes) {+ if (sidebarSearchOpenFirstNodeTypes.has(node.type)) return node;+ }+ return null;+}