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
fix(shortcuts): scope conflict badges to search results
Abeautifulsnowaab0526f52a7
diff --git a/apps/desktop/src/components/editor/EditorSettingsDialog.vue b/apps/desktop/src/components/editor/EditorSettingsDialog.vueindex 809875acf9..36d4fb8f8e 100644--- a/apps/desktop/src/components/editor/EditorSettingsDialog.vue+++ b/apps/desktop/src/components/editor/EditorSettingsDialog.vue@@ -208,7 +208,19 @@ import {} from "@/lib/backend/api";import { createModifierDoubleTapShortcutController } from "@/lib/editor/modifierDoubleTapShortcut";import { eventToModifierOnlyShortcut, eventToShortcut } from "@/lib/editor/keyboardShortcuts";-import { SHORTCUT_DEFINITIONS, countShortcutConflictPairs, findCrossScopeShortcutConflicts, findShortcutConflict, isReservedShortcut, normalizeShortcutSettings, resolveCapturedShortcutEdit, type ShortcutActionId, type ShortcutDefinition, type ShortcutScope } from "@/lib/editor/shortcutRegistry";+import {+ SHORTCUT_DEFINITIONS,+ countShortcutConflictPairs,+ filterShortcutConflictsByVisibleIds,+ findCrossScopeShortcutConflicts,+ findShortcutConflict,+ isReservedShortcut,+ normalizeShortcutSettings,+ resolveCapturedShortcutEdit,+ type ShortcutActionId,+ type ShortcutDefinition,+ type ShortcutScope,+} from "@/lib/editor/shortcutRegistry";import LightTooltip from "@/components/ui/LightTooltip.vue";import { formatShortcutDisplay } from "@/lib/editor/shortcutDisplay";import { COLUMN_NAME_COPY_SEPARATOR_LABELS, COLUMN_NAME_COPY_SEPARATOR_OPTIONS, isColumnNameCopySeparator, type ColumnNameCopySeparator } from "@/lib/dataGrid/dataGridColumnNameCopy";@@ -2173,9 +2185,7 @@ const shortcutConflicts = computed(() => Object.keys(shortcutConflictMap.value)// 有意的设计(find / focusSearch 默认都是 Mod+F,运行时按焦点路由),所以这里// 只用于展示;normalizeShortcutSettings 的占用判定依旧只看同作用域。const crossScopeShortcutConflicts = computed(() => findCrossScopeShortcutConflicts(editShortcuts.value));-const crossScopeShortcutConflictIds = computed(() => Object.keys(crossScopeShortcutConflicts.value) as ShortcutActionId[]);const shortcutConflictPairCount = computed(() => countShortcutConflictPairs(shortcutConflictMap.value));-const crossScopeShortcutPairCount = computed(() => countShortcutConflictPairs(crossScopeShortcutConflicts.value));const sqlShortcutConflicts = computed(() => findSqlShortcutConflicts(editSqlShortcuts.value, editShortcuts.value));const hasSqlShortcutConflicts = computed(() => sqlShortcutConflicts.value.length > 0);const shortcutSearchQuery = ref("");@@ -2218,6 +2228,19 @@ const filteredShortcutDefinitions = computed(() => {});});+// 搜索时顶部徽章与组头摘要要和列表同口径:冲突判定仍全局(上面两个 find* 的+// 输入不变),展示层只统计“可见行或其冲突对方”参与的冲突,清空搜索即恢复+// 全局。应用门禁(页脚“冲突阻止应用”与 Apply 禁用)刻意保持全局口径,不随+// 搜索缩小——保存约束与当前视图无关。+const shortcutSearchActive = computed(() => shortcutSearchQuery.value.trim().length > 0);+const visibleShortcutIds = computed(() => new Set(filteredShortcutDefinitions.value.map((definition) => definition.id)));+const visibleShortcutConflictMap = computed(() => (shortcutSearchActive.value ? filterShortcutConflictsByVisibleIds(shortcutConflictMap.value, visibleShortcutIds.value) : shortcutConflictMap.value));+const visibleCrossScopeShortcutConflicts = computed(() => (shortcutSearchActive.value ? filterShortcutConflictsByVisibleIds(crossScopeShortcutConflicts.value, visibleShortcutIds.value) : crossScopeShortcutConflicts.value));+const visibleShortcutConflictIds = computed(() => Object.keys(visibleShortcutConflictMap.value) as ShortcutActionId[]);+const visibleCrossScopeShortcutConflictIds = computed(() => Object.keys(visibleCrossScopeShortcutConflicts.value) as ShortcutActionId[]);+const visibleShortcutConflictPairCount = computed(() => countShortcutConflictPairs(visibleShortcutConflictMap.value));+const visibleCrossScopeShortcutPairCount = computed(() => countShortcutConflictPairs(visibleCrossScopeShortcutConflicts.value));+// 二级归类:快捷键页签按作用域分组展示。顺序即运行时优先级——越外层先响应,// 用户读到的顺序与事件实际分发顺序一致。const SHORTCUT_SCOPE_ORDER: readonly ShortcutScope[] = ["global", "editor", "grid", "search", "sidebar"];@@ -2253,6 +2276,8 @@ interface ShortcutScopeGroup {unboundCount: number;conflictCount: number;crossScopeCount: number;+ conflictPairCount: number;+ crossScopePairCount: number;}// 计数一律基于“当前可见行”(受搜索过滤影响):组头是它下方那份列表的摘要,@@ -2260,6 +2285,8 @@ interface ShortcutScopeGroup {const shortcutScopeGroups = computed<ShortcutScopeGroup[]>(() =>SHORTCUT_SCOPE_ORDER.map((scope) => {const definitions = filteredShortcutDefinitions.value.filter((definition) => definition.scope === scope);+ // 组内“N 组重复”与上方徽章同口径:判定全局,统计只看“可见行或其冲突对方”。+ const groupIds = new Set(definitions.map((definition) => definition.id));return {scope,label: t(shortcutScopeLabelKey(scope)),@@ -2268,6 +2295,8 @@ const shortcutScopeGroups = computed<ShortcutScopeGroup[]>(() =>unboundCount: definitions.filter((definition) => !editShortcuts.value[definition.id]).length,conflictCount: definitions.filter((definition) => shortcutConflictMap.value[definition.id]).length,crossScopeCount: definitions.filter((definition) => (crossScopeShortcutConflicts.value[definition.id] ?? []).length > 0).length,+ conflictPairCount: countShortcutConflictPairs(filterShortcutConflictsByVisibleIds(shortcutConflictMap.value, groupIds)),+ crossScopePairCount: countShortcutConflictPairs(filterShortcutConflictsByVisibleIds(crossScopeShortcutConflicts.value, groupIds)),};}).filter((group) => group.definitions.length > 0),);@@ -9513,17 +9542,20 @@ onUnmounted(() => {<Search class="pointer-events-none absolute top-1/2 left-3 h-4 w-4 -translate-y-1/2 text-muted-foreground" /><Input v-model="shortcutSearchQuery" autocomplete="off" :placeholder="t('settings.shortcutSearchPlaceholder')" class="h-9 pl-9 text-sm" /></div>- <!-- 冲突摘只需计数,明细进浮层:不再用整条横幅占掉列表高度。 -->- <LightTooltip v-if="shortcutConflicts.length > 0" :text="t('settings.shortcutConflictSummaryTooltip', { count: shortcutConflicts.length, pairs: shortcutConflictPairCount })">+ <!-- 冲突摘要只需计数,明细进浮层:不再用整条横幅占掉列表高度。+ 计数随搜索同口径(见 visibleShortcutConflict* computeds);+ 页脚的应用门禁保持全局,不受搜索影响。 -->+ <LightTooltip v-if="visibleShortcutConflictIds.length > 0" :text="t('settings.shortcutConflictSummaryTooltip', { count: visibleShortcutConflictIds.length, pairs: visibleShortcutConflictPairCount })"><span class="inline-flex h-9 shrink-0 cursor-help items-center gap-1.5 rounded-md border border-destructive/25 bg-destructive/10 px-2 text-[11.5px] font-medium tabular-nums text-destructive"><span class="size-1.5 rounded-full bg-current" aria-hidden="true" />- {{ t("settings.shortcutConflictBadge", { count: shortcutConflicts.length }) }}+ {{ t("settings.shortcutConflictBadge", { count: visibleShortcutConflictIds.length }) }}</span></LightTooltip>- <LightTooltip v-if="crossScopeShortcutConflictIds.length > 0" :text="t('settings.shortcutCrossScopeSummaryTooltip', { count: crossScopeShortcutConflictIds.length, pairs: crossScopeShortcutPairCount })">+ <LightTooltip v-if="visibleCrossScopeShortcutConflictIds.length > 0" :text="t('settings.shortcutCrossScopeSummaryTooltip', { count: visibleCrossScopeShortcutConflictIds.length, pairs: visibleCrossScopeShortcutPairCount })"><span class="inline-flex h-9 shrink-0 cursor-help items-center gap-1.5 rounded-md border border-warning/30 bg-warning/10 px-2 text-[11.5px] font-medium tabular-nums text-warning"><span class="size-1.5 rounded-full bg-current" aria-hidden="true" />- {{ t("settings.shortcutCrossScopeBadge", { count: crossScopeShortcutConflictIds.length }) }}+ <!-- 黄色徽章按“组”(pairs)计数,避免与行级绑定条目数混淆。 -->+ {{ t("settings.shortcutCrossScopeBadge", { count: visibleCrossScopeShortcutPairCount }) }}</span></LightTooltip></div>@@ -9557,10 +9589,10 @@ onUnmounted(() => {{{ t("settings.shortcutGroupUnbound", { count: group.unboundCount }) }}</span></LightTooltip>- <LightTooltip v-if="group.conflictCount > 0" :text="t('settings.shortcutConflictSummaryTooltip', { count: group.conflictCount, pairs: shortcutConflictPairCount })">+ <LightTooltip v-if="group.conflictCount > 0" :text="t('settings.shortcutConflictSummaryTooltip', { count: group.conflictCount, pairs: group.conflictPairCount })"><span class="inline-flex shrink-0 cursor-help items-center gap-1 text-[11px] font-medium tabular-nums text-destructive"> <span class="size-[5px] rounded-full bg-current" aria-hidden="true" />{{ group.conflictCount }} </span></LightTooltip>- <LightTooltip v-if="group.crossScopeCount > 0" :text="t('settings.shortcutCrossScopeSummaryTooltip', { count: group.crossScopeCount, pairs: crossScopeShortcutPairCount })">+ <LightTooltip v-if="group.crossScopeCount > 0" :text="t('settings.shortcutCrossScopeSummaryTooltip', { count: group.crossScopeCount, pairs: group.crossScopePairCount })"><span class="inline-flex shrink-0 cursor-help items-center gap-1 text-[11px] font-medium tabular-nums text-warning"> <span class="size-[5px] rounded-full bg-current" aria-hidden="true" />{{ group.crossScopeCount }} </span></LightTooltip><span class="ml-auto hidden truncate text-[11px] text-muted-foreground xl:block">{{ group.hint }}</span>diff --git a/apps/desktop/src/components/editor/__tests__/EditorSettingsDialog.shortcutScopeGroups.integration.spec.ts b/apps/desktop/src/components/editor/__tests__/EditorSettingsDialog.shortcutScopeGroups.integration.spec.tsindex 76f8556c98..df9ecfe782 100644--- a/apps/desktop/src/components/editor/__tests__/EditorSettingsDialog.shortcutScopeGroups.integration.spec.ts+++ b/apps/desktop/src/components/editor/__tests__/EditorSettingsDialog.shortcutScopeGroups.integration.spec.ts@@ -18,7 +18,16 @@ const hoisted = vi.hoisted(() => ({ shortcuts: {} as Record<string, string> }));vi.mock("vue-i18n", async () => {const { ref } = await import("vue");const locale = ref("en");- const t = (key: string) => key;+ // Interpolate params into the returned string so count assertions can read+ // them (real vue-i18n would fold them into the message text).+ const t = (key: string, params?: Record<string, unknown>) => {+ if (!params) return key;+ const suffix = Object.keys(params)+ .sort()+ .map((name) => `${name}=${String(params[name])}`)+ .join(" ");+ return suffix ? `${key} ${suffix}` : key;+ };return {createI18n: () => ({ global: { t, locale }, install: () => undefined }),useI18n: () => ({ t, locale }),@@ -351,4 +360,72 @@ describe("EditorSettingsDialog shortcut scope grouping (behaviour)", () => {expect(positions).toEqual([...positions].sort((a, b) => a - b));expect(positions.every((index) => index >= 0)).toBe(true);});++ it("scopes the amber cross-scope badge to the search results and restores the global count on clear", async () => {+ hoisted.shortcuts = defaults();+ const host = await mountShortcutsTab();++ const crossBadge = () => shortcutsPane(host).querySelector<HTMLElement>('span[class*="border-warning/30"]');+ const conflictBadge = () => shortcutsPane(host).querySelector<HTMLElement>('span[class*="border-destructive/25"]');++ // 未搜索:全局口径(默认键位 6 组跨域同键),且默认无同作用域阻断冲突。+ expect(crossBadge()!.textContent!.trim()).toBe("settings.shortcutCrossScopeBadge count=6");+ expect(conflictBadge()).toBeNull();++ const search = shortcutsPane(host).querySelector<HTMLInputElement>('input[placeholder="settings.shortcutSearchPlaceholder"]')!;++ // 搜索只留下 editTableStructure 一行:对方 viewTableDdl 被过滤掉,但冲突+ // 判定仍基于全局绑定,这组重叠必须继续计入(恰好 1 组)。+ search.value = "shortcutEditTableStructure";+ search.dispatchEvent(new Event("input", { bubbles: true }));+ await flushAsyncUpdates();+ expect(rows(host).length).toBe(1);+ expect(crossBadge()!.textContent!.trim()).toBe("settings.shortcutCrossScopeBadge count=1");++ // 无搜索结果:徽章随空结果隐藏。+ search.value = "noSuchShortcutZZZ";+ search.dispatchEvent(new Event("input", { bubbles: true }));+ await flushAsyncUpdates();+ expect(crossBadge()).toBeNull();++ // 清空搜索:恢复全局口径。+ search.value = "";+ search.dispatchEvent(new Event("input", { bubbles: true }));+ await flushAsyncUpdates();+ expect(crossBadge()!.textContent!.trim()).toBe("settings.shortcutCrossScopeBadge count=6");+ });++ it("scopes the red same-scope badge to the search results while the footer gate stays global", async () => {+ const base = defaults();+ hoisted.shortcuts = defaults();+ const host = await mountShortcutsTab();++ const conflictBadge = () => shortcutsPane(host).querySelector<HTMLElement>('span[class*="border-destructive/25"]');+ const search = shortcutsPane(host).querySelector<HTMLInputElement>('input[placeholder="settings.shortcutSearchPlaceholder"]')!;++ // explainSql 与 formatSql 同属 editor 作用域:走真实捕获输入重绑成同键,+ // 制造一组阻断冲突(草稿被改动后页脚门禁才会出现,与产品语义一致)。+ rowFor(host, "explainSql").querySelector<HTMLButtonElement>("button")!.click();+ await flushAsyncUpdates();+ inputFor(host, "explainSql").dispatchEvent(shortcutKeyEvent(base.formatSql));+ await flushAsyncUpdates();++ // 全局:冲突映射双向各记一行,2 项冲突(1 组重复)。+ expect(conflictBadge()!.textContent!.trim()).toBe("settings.shortcutConflictBadge count=2");+ expect(hasFooterBlockerReason(host)).toBe(true);++ // 搜索只留 formatSql:对方 explainSql 不可见,但冲突真实存在,仍计入。+ search.value = "shortcutFormatSql";+ search.dispatchEvent(new Event("input", { bubbles: true }));+ await flushAsyncUpdates();+ expect(conflictBadge()!.textContent!.trim()).toBe("settings.shortcutConflictBadge count=2");+ expect(hasFooterBlockerReason(host)).toBe(true);++ // 当前结果无冲突:徽章隐藏,但页脚全局门禁不随搜索消失。+ search.value = "shortcutUndo";+ search.dispatchEvent(new Event("input", { bubbles: true }));+ await flushAsyncUpdates();+ expect(conflictBadge()).toBeNull();+ expect(hasFooterBlockerReason(host)).toBe(true);+ });});diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.tsindex 179100fd61..59d83a3b3f 100644--- a/apps/desktop/src/i18n/locales/zh-CN.ts+++ b/apps/desktop/src/i18n/locales/zh-CN.ts@@ -9083,7 +9083,7 @@ export default withEnglishFallback({shortcutConflictBadge: "{count} 项冲突",shortcutConflictTooltip: "与「{label}」({scope})同键。同一作用域内一个组合只能绑定一个操作,需改掉其中一个才能应用。",shortcutConflictSummaryTooltip: "同作用域冲突 {count} 项({pairs} 组重复)。同一作用域内一个组合只能绑定一个操作,解决前无法应用。",- shortcutCrossScopeBadge: "{count} 项跨域同键",+ shortcutCrossScopeBadge: "{count} 组跨域同键",shortcutCrossScopeTooltip: "与 {targets} 同键。不同作用域各自生效,按焦点路由,同一时刻只触发一个;无需处理。",shortcutCrossScopeTooltipSeparator: "、",shortcutCrossScopeSummaryTooltip: "跨作用域同键 {count} 项({pairs} 组重复)。不同作用域各自生效,同一时刻只触发一个;仅作提示,不影响应用。",diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.tsindex 6bb561c2e7..983ef747a1 100644--- a/apps/desktop/src/i18n/locales/zh-TW.ts+++ b/apps/desktop/src/i18n/locales/zh-TW.ts@@ -7412,7 +7412,7 @@ export default withEnglishFallback({shortcutConflictBadge: "{count} 項衝突",shortcutConflictTooltip: "與「{label}」({scope})同鍵。同一作用域內一個組合只能綁定一個操作,需改掉其中一個才能套用。",shortcutConflictSummaryTooltip: "同作用域衝突 {count} 項({pairs} 組重複)。同一作用域內一個組合只能綁定一個操作,解決前無法套用。",- shortcutCrossScopeBadge: "{count} 項跨域同鍵",+ shortcutCrossScopeBadge: "{count} 組跨域同鍵",shortcutCrossScopeTooltip: "與 {targets} 同鍵。不同作用域各自生效,依焦點路由,同一時刻只觸發一個;無需處理。",shortcutCrossScopeTooltipSeparator: "、",shortcutCrossScopeSummaryTooltip: "跨作用域同鍵 {count} 項({pairs} 組重複)。不同作用域各自生效,同一時刻只觸發一個;僅作提示,不影響套用。",diff --git a/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts b/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.tsindex 4a6af32707..4eeed38d79 100644--- a/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts+++ b/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts@@ -4,6 +4,7 @@ import {closeOtherTabsDefaultShortcut,countShortcutConflictPairs,DEFAULT_SHORTCUT_SETTINGS,+ filterShortcutConflictsByVisibleIds,findCrossScopeShortcutConflicts,findShortcutConflict,foldAllDefaultShortcut,@@ -586,6 +587,32 @@ describe("shortcutRegistry editor actions", () => {});});+ describe("filterShortcutConflictsByVisibleIds", () => {+ it("keeps a conflict whose partner row is filtered out (detection stays global)", () => {+ // find(editor) <-> focusSearch(global) 默认跨作用域同键;搜索只留下 find+ // 一行时,这组重叠仍要计入徽章——对方行被过滤不代表冲突消失。+ const conflicts = findCrossScopeShortcutConflicts(DEFAULT_SHORTCUT_SETTINGS);+ const filtered = filterShortcutConflictsByVisibleIds(conflicts, new Set<ShortcutActionId>(["find"]));+ expect(filtered.find).toContain("focusSearch");+ expect(filtered.focusSearch).toContain("find");+ expect(Object.keys(filtered)).not.toContain("explainSql");+ });++ it("handles the L1 same-scope shape and the empty visible set", () => {+ const seeded = normalizeShortcutSettings({ explainSql: DEFAULT_SHORTCUT_SETTINGS.formatSql });+ const l1: Partial<Record<ShortcutActionId, ShortcutActionId>> = {};+ for (const definition of SHORTCUT_DEFINITIONS) {+ const conflict = findShortcutConflict(definition.id, seeded[definition.id], seeded);+ if (conflict) l1[definition.id] = conflict;+ }+ expect(Object.keys(l1).sort()).toEqual(["explainSql", "formatSql"]);+ // 只留冲突一方时整组保留;可见集与冲突无关或为空时返回空映射。+ expect(filterShortcutConflictsByVisibleIds(l1, new Set<ShortcutActionId>(["explainSql"]))).toEqual(l1);+ expect(filterShortcutConflictsByVisibleIds(l1, new Set<ShortcutActionId>(["goToColumn"]))).toEqual({});+ expect(filterShortcutConflictsByVisibleIds(l1, new Set())).toEqual({});+ });+ });+describe("gotoLine", () => {it("resolves the platform default and maps it to the CodeMirror key", () => {// macOS 的 ⌃G 已分配给「选中下一个相同词」(JetBrains 风格),沿用diff --git a/apps/desktop/src/lib/editor/shortcutRegistry.ts b/apps/desktop/src/lib/editor/shortcutRegistry.tsindex 352b8bb793..29c109fe2e 100644--- a/apps/desktop/src/lib/editor/shortcutRegistry.ts+++ b/apps/desktop/src/lib/editor/shortcutRegistry.ts@@ -996,3 +996,28 @@ export function countShortcutConflictPairs(conflicts: Partial<Record<ShortcutAct}return pairs.size;}++/**+ * 按当前搜索的可见行过滤冲突**展示**(不改变判定)。+ *+ * 冲突判定始终基于全局绑定(见上方两个 find*),但顶部徽章、组头摘要要与+ * 列表同口径:只统计“可见行或其冲突对方”参与的冲突。取“或”是因为对方被+ * 搜索过滤掉时,冲突本身仍然真实存在,不能从统计里消失——与 Eclipse/+ * DBeaver Keys 偏好页一致:过滤器只作用于视图,冲突模型始终全局。+ *+ * 同时接受 L1(每行单个对方)与 L2(每行多个对方)两种形状,与+ * `countShortcutConflictPairs` 的口径约定一致。空可见集返回空映射,+ * 让徽章在“无搜索结果”时自然隐藏。+ */+export function filterShortcutConflictsByVisibleIds<T extends ShortcutActionId | ShortcutActionId[]>(conflicts: Partial<Record<ShortcutActionId, T>>, visibleIds: ReadonlySet<ShortcutActionId>): Partial<Record<ShortcutActionId, T>> {+ if (visibleIds.size === 0) return {};+ const filtered: Partial<Record<ShortcutActionId, T>> = {};+ for (const [actionId, value] of Object.entries(conflicts)) {+ if (!value) continue;+ const others = (Array.isArray(value) ? value : [value]) as ShortcutActionId[];+ if (visibleIds.has(actionId as ShortcutActionId) || others.some((other) => visibleIds.has(other))) {+ filtered[actionId as ShortcutActionId] = value;+ }+ }+ return filtered;+}