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。

feat(shortcuts): support modifier double taps for search

二丫讲梵5eaccd306269
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue
index 96fceabc39..f0280cdb72 100644
--- a/apps/desktop/src/App.vue
+++ b/apps/desktop/src/App.vue
@@ -151,6 +151,7 @@ import {
} from "@/lib/editor/keyboardShortcuts";
import { canSaveSqlTab } from "@/lib/tabs/sqlTabSaveTarget";
import { initialTabSwitcherSelection, moveTabSwitcherSelection, tabSwitcherOrder } from "@/lib/tabs/tabSwitcher";
+import { createModifierDoubleTapShortcutController, isModifierDoubleTapShortcut, matchesModifierDoubleTapShortcut } from "@/lib/editor/modifierDoubleTapShortcut";
import { createTabSwitcherKeyboardController } from "@/lib/tabs/tabSwitcherKeyboard";
import { formatShortcutDisplay } from "@/lib/editor/shortcutDisplay";
import { supportsSqlFileExecution } from "@/lib/database/databaseCapabilities";
@@ -4026,7 +4027,35 @@ function closeTabSwitcher(commit: boolean) {
if (tab) activateQueryTab(tab.id);
}
+const modifierDoubleTapSearch = createModifierDoubleTapShortcutController();
+watch(
+ () => [settingsStore.editorSettings.shortcuts.quickOpen, settingsStore.editorSettings.shortcuts.globalSearch],
+ () => modifierDoubleTapSearch.reset(),
+ { flush: "sync" },
+);
+
+function canCaptureModifierDoubleTapSearch(e: KeyboardEvent): boolean {
+ const target = e.target instanceof Element ? e.target : document.activeElement;
+ const shortcuts = settingsStore.editorSettings.shortcuts;
+ const enabled = isModifierDoubleTapShortcut(shortcuts.quickOpen) || isModifierDoubleTapShortcut(shortcuts.globalSearch);
+ // Capture runs before the settings input can stop propagation.
+ if (e.defaultPrevented || showTabSwitcher.value || !enabled || target?.closest("[data-shortcut-input], [data-sql-shortcut-input]")) {
+ modifierDoubleTapSearch.reset();
+ return false;
+ }
+ return true;
+}
+
function handleKeyup(e: KeyboardEvent) {
+ const shortcut = canCaptureModifierDoubleTapSearch(e) ? modifierDoubleTapSearch.handleKeyup(e) : null;
+ const shortcuts = settingsStore.editorSettings.shortcuts;
+ const quickOpenMatched = !!shortcut && matchesModifierDoubleTapShortcut(shortcut, shortcuts.quickOpen);
+ if (shortcut && (quickOpenMatched || matchesModifierDoubleTapShortcut(shortcut, shortcuts.globalSearch))) {
+ e.preventDefault();
+ e.stopPropagation();
+ quickOpenForceContent.value = !quickOpenMatched;
+ showQuickOpen.value = true;
+ }
tabSwitcherKeyboard.handleKeyup(e);
}
@@ -4035,6 +4064,9 @@ function handleTabSwitcherKeydownCapture(e: KeyboardEvent) {
}
function handleGlobalSearchKeydownCapture(e: KeyboardEvent) {
+ if (canCaptureModifierDoubleTapSearch(e)) modifierDoubleTapSearch.handleKeydown(e);
+ const target = e.target instanceof Element ? e.target : document.activeElement;
+ if (target?.closest("[data-shortcut-input], [data-sql-shortcut-input]")) return;
if (e.defaultPrevented || !isGlobalSearchShortcut(e, settingsStore.editorSettings.shortcuts)) return;
e.preventDefault();
e.stopPropagation();
@@ -4051,10 +4083,12 @@ function handleAuxiliarySearchKeydownCapture(e: KeyboardEvent) {
}
function handleTabSwitcherWindowBlur() {
+ modifierDoubleTapSearch.reset();
tabSwitcherKeyboard.handleWindowBlur();
}
function handleTabSwitcherVisibilityChange() {
+ modifierDoubleTapSearch.reset();
tabSwitcherKeyboard.handleVisibilityChange(document.visibilityState);
}
@@ -4637,6 +4671,9 @@ onMounted(async () => {
});
applyTheme();
void applyUiScale(settingsStore.editorSettings.uiScale);
+ window.addEventListener("pointerdown", modifierDoubleTapSearch.cancel, true);
+ window.addEventListener("focusin", modifierDoubleTapSearch.cancel, true);
+ window.addEventListener("compositionstart", modifierDoubleTapSearch.cancel, true);
window.addEventListener("keydown", handleGlobalSearchKeydownCapture, true);
window.addEventListener("keydown", handleTabSwitcherKeydownCapture, true);
window.addEventListener("keydown", handleAuxiliarySearchKeydownCapture, true);
@@ -4729,6 +4766,10 @@ onUnmounted(() => {
clearInterval(updateCheckTimer);
}
window.removeEventListener("keydown", handleNativeSelectAll, true);
+ modifierDoubleTapSearch.reset();
+ window.removeEventListener("pointerdown", modifierDoubleTapSearch.cancel, true);
+ window.removeEventListener("focusin", modifierDoubleTapSearch.cancel, true);
+ window.removeEventListener("compositionstart", modifierDoubleTapSearch.cancel, true);
window.removeEventListener("keydown", handleGlobalSearchKeydownCapture, true);
window.removeEventListener("keydown", handleTabSwitcherKeydownCapture, true);
window.removeEventListener("keydown", handleAuxiliarySearchKeydownCapture, true);
diff --git a/apps/desktop/src/components/editor/EditorSettingsDialog.vue b/apps/desktop/src/components/editor/EditorSettingsDialog.vue
index dee49d54fa..809875acf9 100644
--- a/apps/desktop/src/components/editor/EditorSettingsDialog.vue
+++ b/apps/desktop/src/components/editor/EditorSettingsDialog.vue
@@ -206,6 +206,7 @@ import {
type SyncSnapshotCatalog,
type WebDavConfig,
} 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 LightTooltip from "@/components/ui/LightTooltip.vue";
@@ -869,6 +870,8 @@ let tableColumnTemplatePointerDragCleanup: (() => void) | null = null;
const editSqlFormatter = ref<SqlFormatterSettings>(normalizeSqlFormatterSettings(settingsStore.editorSettings.sqlFormatter));
const sqlFormatterConfigValid = ref(true);
const editingShortcutId = ref<ShortcutActionId | null>(null);
+const modifierDoubleTapRecorder = createModifierDoubleTapShortcutController();
+watch(editingShortcutId, () => modifierDoubleTapRecorder.reset(), { flush: "sync" });
const editSidebarActivation = ref(settingsStore.editorSettings.sidebarActivation);
const editSidebarObjectDisplay = ref(settingsStore.editorSettings.sidebarObjectDisplay);
const sidebarObjectDisplayHelp = ref<"grouped" | "simple" | null>(null);
@@ -3154,8 +3157,21 @@ function onShortcutKeydown(actionId: ShortcutActionId, event: KeyboardEvent) {
return;
}
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === actionId);
+ if (definition?.supportsModifierDoubleTap) modifierDoubleTapRecorder.handleKeydown(event);
const shortcut = definition?.inputKind === "modifier-only" ? eventToModifierOnlyShortcut(event) : eventToShortcut(event);
if (!shortcut) return;
+ commitCapturedShortcut(actionId, shortcut);
+}
+
+function onShortcutKeyup(actionId: ShortcutActionId, event: KeyboardEvent) {
+ if (editingShortcutId.value !== actionId || !shortcutDefinitionById(actionId)?.supportsModifierDoubleTap) return;
+ event.stopPropagation();
+ const shortcut = modifierDoubleTapRecorder.handleKeyup(event);
+ if (shortcut) commitCapturedShortcut(actionId, shortcut);
+}
+
+function commitCapturedShortcut(actionId: ShortcutActionId, shortcut: string) {
+ modifierDoubleTapRecorder.reset();
// macOS 上 ⌘H/⌥⌘H 由系统保留(Hide / Hide Others),配置层一旦绑定并在
// CodeMirror 中 preventDefault,AppKit 菜单的 key equivalent 就无法触发
// (#9068 的配置层复现),故此处输入时直接拒绝。
@@ -3215,6 +3231,7 @@ function cancelShortcutEdit() {
}
function resetShortcut(actionId: ShortcutActionId) {
+ modifierDoubleTapRecorder.reset();
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === actionId);
if (!definition) return;
// The static definition default is the macOS literal for a few actions
@@ -3228,6 +3245,7 @@ function resetShortcut(actionId: ShortcutActionId) {
}
function clearShortcut(actionId: ShortcutActionId) {
+ modifierDoubleTapRecorder.reset();
editShortcuts.value = { ...editShortcuts.value, [actionId]: "" };
}
@@ -5198,6 +5216,10 @@ watch(
);
onMounted(() => {
+ window.addEventListener("blur", modifierDoubleTapRecorder.reset);
+ document.addEventListener("visibilitychange", modifierDoubleTapRecorder.reset);
+ window.addEventListener("pointerdown", modifierDoubleTapRecorder.cancel, true);
+ window.addEventListener("compositionstart", modifierDoubleTapRecorder.cancel, true);
void refreshWebDavPasswordStatus();
checkLayoutDescTruncation();
initTruncationObservers();
@@ -5205,6 +5227,11 @@ onMounted(() => {
});
onUnmounted(() => {
+ window.removeEventListener("blur", modifierDoubleTapRecorder.reset);
+ document.removeEventListener("visibilitychange", modifierDoubleTapRecorder.reset);
+ window.removeEventListener("pointerdown", modifierDoubleTapRecorder.cancel, true);
+ window.removeEventListener("compositionstart", modifierDoubleTapRecorder.cancel, true);
+ modifierDoubleTapRecorder.reset();
clearThemePaletteOptionPreview();
clearUiFontOptionPreview();
restoreLocaleOptionPreview();
@@ -7309,6 +7336,10 @@ onUnmounted(() => {
class="h-7 w-auto min-w-12 max-w-64 shrink-0 cursor-default rounded-[6px] border border-transparent bg-background px-2.5 text-center font-mono text-[13px] font-semibold text-foreground/75 shadow-inner outline-none selection:bg-transparent placeholder:text-muted-foreground aria-invalid:border-destructive/70 aria-invalid:text-destructive aria-invalid:ring-destructive/20"
:class="editingShortcutId === definition.id ? 'max-w-64 cursor-text border-border/80 bg-background text-left text-foreground shadow-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/35' : ''"
@keydown="(event: KeyboardEvent) => onShortcutKeydown(definition.id, event)"
+ @keyup="(event: KeyboardEvent) => onShortcutKeyup(definition.id, event)"
+ @blur="modifierDoubleTapRecorder.reset"
+ @compositionstart="modifierDoubleTapRecorder.cancel"
+ :title="definition.supportsModifierDoubleTap ? t('settings.shortcutModifierDoubleTapHint') : undefined"
/>
<Button
v-if="editingShortcutId !== definition.id"
@@ -9573,6 +9604,10 @@ onUnmounted(() => {
class="settings-shortcut-pill h-7 w-auto min-w-12 max-w-64 shrink-0 cursor-default rounded-[6px] border border-transparent bg-muted px-2.5 text-center font-mono text-[13px] font-semibold text-foreground/75 shadow-inner outline-none selection:bg-transparent placeholder:text-muted-foreground aria-invalid:border-destructive/55 aria-invalid:text-destructive"
:class="editingShortcutId === definition.id ? 'max-w-64 cursor-text border-border/80 bg-background text-left text-foreground shadow-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/35' : ''"
@keydown="(event: KeyboardEvent) => onShortcutKeydown(definition.id, event)"
+ @keyup="(event: KeyboardEvent) => onShortcutKeyup(definition.id, event)"
+ @blur="modifierDoubleTapRecorder.reset"
+ @compositionstart="modifierDoubleTapRecorder.cancel"
+ :title="definition.supportsModifierDoubleTap ? t('settings.shortcutModifierDoubleTapHint') : undefined"
/>
</LightTooltip>
<Button
diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.ts
index a8493933c1..c448c1821c 100644
--- a/apps/desktop/src/i18n/locales/az.ts
+++ b/apps/desktop/src/i18n/locales/az.ts
@@ -8018,6 +8018,7 @@ export default withEnglishFallback({
shortcutCrossScopeSummaryTooltip: "{count} əhatələr arası eyni düymə ({pairs} təkrarlanan cüt). Hər əhatə dairəsi öz kombinasiyasını həll edir, ona görə eyni anda yalnızca biri işə düşür; yalnız məlumat üçündür və tətbiqi maneə törətmir.",
shortcutConflictBlocksApply: "Eyni əhatə dairəsində {count} toqquşma var ({pairs} təkrarlanan cüt)",
shortcutPressShortcut: "Qısayol düymələrini bas",
+ shortcutModifierDoubleTapHint: "Düymə kombinasiyasını basın və ya eyni dəyişdirici düyməni sürətlə iki dəfə basıb buraxın (Shift, Cmd, Ctrl, Alt).",
shortcutSearchPlaceholder: "Qısayolları axtar",
shortcutSearchNoResults: "Axtarışınıza uyğun qısayol yoxdur.",
shortcutConflict: "Bu qısayol eyni əhatə dairəsində başqa əməliyyatla ziddiyyət təşkil edir.",
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index 9f9b61dee2..551f0f7f4f 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -9089,6 +9089,7 @@ export default {
shortcutCrossScopeSummaryTooltip: "{count} cross-scope overlaps ({pairs} duplicate pairs). Different scopes resolve their own bindings, so only one fires at a time; informational only, it does not block applying.",
shortcutConflictBlocksApply: "{count} conflicts within one scope ({pairs} duplicate pairs)",
shortcutPressShortcut: "Press shortcut",
+ shortcutModifierDoubleTapHint: "Press a key combination, or quickly press and release the same modifier twice (e.g. Shift, Cmd, Ctrl, Alt).",
shortcutSearchPlaceholder: "Search shortcuts",
shortcutSearchNoResults: "No shortcuts match your search.",
shortcutConflict: "This shortcut conflicts with another action in the same scope.",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index 400b9ee05b..74a9cdd84a 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -8325,6 +8325,7 @@ export default withEnglishFallback({
shortcutCrossScopeSummaryTooltip: "{count} coincidencias entre ámbitos ({pairs} pares duplicados). Cada ámbito resuelve su propia combinación, así que solo se activa una a la vez; es solo informativo y no bloquea la aplicación.",
shortcutConflictBlocksApply: "Hay {count} conflictos en un mismo ámbito ({pairs} pares duplicados)",
shortcutPressShortcut: "Presiona un atajo",
+ shortcutModifierDoubleTapHint: "Pulsa una combinación de teclas o pulsa y suelta rápidamente el mismo modificador dos veces (Shift, Cmd, Ctrl, Alt).",
shortcutSearchPlaceholder: "Buscar atajos",
shortcutSearchNoResults: "Ningún atajo coincide con la búsqueda.",
shortcutConflict: "Este atajo entra en conflicto con otra acción del mismo ámbito.",
diff --git a/apps/desktop/src/i18n/locales/id.ts b/apps/desktop/src/i18n/locales/id.ts
index 231e1198c5..17263019c0 100644
--- a/apps/desktop/src/i18n/locales/id.ts
+++ b/apps/desktop/src/i18n/locales/id.ts
@@ -8807,6 +8807,7 @@ export default withEnglishFallback({
shortcutCrossScopeSummaryTooltip: "{count} tumpang tindih lintas cakupan ({pairs} pasangan duplikat). Cakupan yang berbeda menyelesaikan bindingnya masing-masing, sehingga hanya satu yang aktif pada satu waktu; hanya informasional, tidak menghalangi penerapan.",
shortcutConflictBlocksApply: "{count} konflik dalam satu cakupan ({pairs} pasangan duplikat)",
shortcutPressShortcut: "Tekan pintasan",
+ shortcutModifierDoubleTapHint: "Tekan kombinasi tombol, atau tekan dan lepaskan tombol pengubah yang sama dua kali dengan cepat (Shift, Cmd, Ctrl, Alt).",
shortcutSearchPlaceholder: "Cari pintasan",
shortcutSearchNoResults: "Tidak ada pintasan yang cocok dengan pencarian Anda.",
shortcutConflict: "Pintasan ini berkonflik dengan aksi lain pada cakupan yang sama.",
diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts
index ed3e034c63..96d350debf 100644
--- a/apps/desktop/src/i18n/locales/it.ts
+++ b/apps/desktop/src/i18n/locales/it.ts
@@ -8088,6 +8088,7 @@ export default withEnglishFallback({
shortcutCrossScopeSummaryTooltip: "{count} sovrapposizioni tra ambiti ({pairs} coppie duplicate). Ogni ambito risolve la propria combinazione, quindi se ne attiva una alla volta; è solo informativo e non blocca l’applicazione.",
shortcutConflictBlocksApply: "Ci sono {count} conflitti nello stesso ambito ({pairs} coppie duplicate)",
shortcutPressShortcut: "Premi scorciatoia",
+ shortcutModifierDoubleTapHint: "Premi una combinazione di tasti oppure premi e rilascia rapidamente lo stesso modificatore due volte (Shift, Cmd, Ctrl, Alt).",
shortcutSearchPlaceholder: "Cerca scorciatoie",
shortcutSearchNoResults: "Nessuna scorciatoia corrisponde alla ricerca.",
shortcutConflict: "Questa scorciatoia è in conflitto con un'altra azione nello stesso ambito.",
diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts
index 3bcae9833c..a67b4d79e0 100644
--- a/apps/desktop/src/i18n/locales/ja.ts
+++ b/apps/desktop/src/i18n/locales/ja.ts
@@ -8080,6 +8080,7 @@ export default withEnglishFallback({
shortcutCrossScopeSummaryTooltip: "スコープ間の重複 {count} 件(重複 {pairs} 組)。スコープごとに解決されるため同時に 1 つだけ動作します。提示のみで、適用は妨げません。",
shortcutConflictBlocksApply: "同一スコープの競合が {count} 件あります(重複 {pairs} 組)",
shortcutPressShortcut: "ショートカットを押してください",
+ shortcutModifierDoubleTapHint: "キーの組み合わせ、または同じ修飾キー(Shift、Cmd、Ctrl、Alt など)を素早く2回押して離してください。",
shortcutSearchPlaceholder: "ショートカットを検索",
shortcutSearchNoResults: "一致するショートカットはありません。",
shortcutConflict: "このショートカットは同じスコープ内の別のアクションと競合しています。",
diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.ts
index 79840d701b..0ce6704d41 100644
--- a/apps/desktop/src/i18n/locales/ko.ts
+++ b/apps/desktop/src/i18n/locales/ko.ts
@@ -7937,6 +7937,7 @@ export default withEnglishFallback({
shortcutCrossScopeSummaryTooltip: "스코프 간 중복 {count}개(중복 {pairs}쌍). 스코프별로 처리되므로 동시에 하나만 동작합니다. 안내용이며 적용을 막지 않습니다.",
shortcutConflictBlocksApply: "같은 스코프 충돌 {count}개(중복 {pairs}쌍)",
shortcutPressShortcut: "단축키를 누르세요",
+ shortcutModifierDoubleTapHint: "키 조합을 누르거나 같은 보조 키(Shift, Cmd, Ctrl, Alt 등)를 빠르게 두 번 눌렀다 놓으세요.",
shortcutSearchPlaceholder: "단축키 검색",
shortcutSearchNoResults: "검색과 일치하는 단축키가 없습니다.",
shortcutConflict: "이 단축키는 같은 범위의 다른 작업과 충돌합니다.",
diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts
index de17722171..cb7bc757dd 100644
--- a/apps/desktop/src/i18n/locales/pt-BR.ts
+++ b/apps/desktop/src/i18n/locales/pt-BR.ts
@@ -8086,6 +8086,7 @@ export default withEnglishFallback({
shortcutCrossScopeSummaryTooltip: "{count} sobreposições entre escopos ({pairs} pares duplicados). Cada escopo resolve a própria combinação, então apenas uma é acionada por vez; é apenas informativo e não bloqueia a aplicação.",
shortcutConflictBlocksApply: "Há {count} conflitos no mesmo escopo ({pairs} pares duplicados)",
shortcutPressShortcut: "Pressione o atalho",
+ shortcutModifierDoubleTapHint: "Pressione uma combinação de teclas ou pressione e solte rapidamente o mesmo modificador duas vezes (Shift, Cmd, Ctrl, Alt).",
shortcutSearchPlaceholder: "Pesquisar atalhos",
shortcutSearchNoResults: "Nenhum atalho corresponde à pesquisa.",
shortcutConflict: "Este atalho conflita com outra ação no mesmo escopo.",
diff --git a/apps/desktop/src/i18n/locales/ru.ts b/apps/desktop/src/i18n/locales/ru.ts
index df55d6b919..abb53b20b4 100644
--- a/apps/desktop/src/i18n/locales/ru.ts
+++ b/apps/desktop/src/i18n/locales/ru.ts
@@ -9379,6 +9379,7 @@ export default withEnglishFallback({
shortcutCrossScopeSummaryTooltip: "{count} пересечений между областями ({pairs} дублирующихся пар). Разные области разрешают свои привязки, поэтому срабатывает только одна за раз; это только для сведения и не блокирует применение.",
shortcutConflictBlocksApply: "{count} конфликтов в одной области ({pairs} дублирующихся пар)",
shortcutPressShortcut: "Нажмите сочетание клавиш",
+ shortcutModifierDoubleTapHint: "Нажмите сочетание клавиш или быстро нажмите и отпустите одну и ту же клавишу-модификатор дважды (Shift, Cmd, Ctrl, Alt).",
shortcutSearchPlaceholder: "Поиск сочетаний клавиш",
shortcutSearchNoResults: "Нет сочетаний клавиш, соответствующих запросу.",
shortcutConflict: "Это сочетание клавиш конфликтует с другим действием в той же области.",
diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.ts
index bf848fe794..3258de0239 100644
--- a/apps/desktop/src/i18n/locales/tr.ts
+++ b/apps/desktop/src/i18n/locales/tr.ts
@@ -7919,6 +7919,7 @@ export default withEnglishFallback({
shortcutCrossScopeSummaryTooltip: "{count} kapsamlar arası aynı tuş ({pairs} yinelenen çift). Her kapsam kendi bileşimini çözer, bu yüzden aynı anda yalnızca biri tetiklenir; yalnızca bilgilendirme amaçlıdır ve uygulamayı engellemez.",
shortcutConflictBlocksApply: "Aynı kapsamda {count} çakışma var ({pairs} yinelenen çift)",
shortcutPressShortcut: "Kısayola basın",
+ shortcutModifierDoubleTapHint: "Bir tuş birleşimine basın veya aynı değiştirici tuşa hızla iki kez basıp bırakın (Shift, Cmd, Ctrl, Alt).",
shortcutSearchPlaceholder: "Kısayollarda ara",
shortcutSearchNoResults: "Aramanızla eşleşen kısayol yok.",
shortcutConflict: "Bu kısayol aynı kapsamdaki başka bir eylemle çakışıyor.",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index bd1bfd190a..fe9d2e490c 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -9075,6 +9075,7 @@ export default withEnglishFallback({
shortcutCrossScopeSummaryTooltip: "跨作用域同键 {count} 项({pairs} 组重复)。不同作用域各自生效,同一时刻只触发一个;仅作提示,不影响应用。",
shortcutConflictBlocksApply: "存在 {count} 项同作用域冲突({pairs} 组重复)",
shortcutPressShortcut: "按下快捷键",
+ shortcutModifierDoubleTapHint: "可按下组合键,或快速按下并松开同一个修饰键两次(如 Shift、Cmd、Ctrl、Alt)。",
shortcutSearchPlaceholder: "搜索快捷键",
shortcutSearchNoResults: "没有匹配的快捷键。",
shortcutConflict: "这个快捷键与同一作用域内的其他操作冲突。",
diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts
index ebce3f91e7..157be9b3b3 100644
--- a/apps/desktop/src/i18n/locales/zh-TW.ts
+++ b/apps/desktop/src/i18n/locales/zh-TW.ts
@@ -7404,6 +7404,7 @@ export default withEnglishFallback({
shortcutCrossScopeSummaryTooltip: "跨作用域同鍵 {count} 項({pairs} 組重複)。不同作用域各自生效,同一時刻只觸發一個;僅作提示,不影響套用。",
shortcutConflictBlocksApply: "存在 {count} 項同作用域衝突({pairs} 組重複)",
shortcutPressShortcut: "按下快速鍵",
+ shortcutModifierDoubleTapHint: "可按下組合鍵,或快速按下並放開同一個修飾鍵兩次(如 Shift、Cmd、Ctrl、Alt)。",
shortcutSearchPlaceholder: "搜尋快速鍵",
shortcutSearchNoResults: "沒有符合的快速鍵。",
shortcutConflict: "這個快速鍵與同一作用域內的其他操作衝突。",
diff --git a/apps/desktop/src/lib/__tests__/editor/modifierDoubleTapShortcut.spec.ts b/apps/desktop/src/lib/__tests__/editor/modifierDoubleTapShortcut.spec.ts
new file mode 100644
index 0000000000..df1c266026
--- /dev/null
+++ b/apps/desktop/src/lib/__tests__/editor/modifierDoubleTapShortcut.spec.ts
@@ -0,0 +1,132 @@
+// @vitest-environment happy-dom
+
+import { describe, expect, it } from "vitest";
+import { createModifierDoubleTapShortcutController, isModifierDoubleTapShortcut, matchesModifierDoubleTapShortcut } from "@/lib/editor/modifierDoubleTapShortcut";
+
+function keyEvent(type: "keydown" | "keyup", init: KeyboardEventInit, at: number): KeyboardEvent {
+ const event = new KeyboardEvent(type, init);
+ Object.defineProperty(event, "timeStamp", { value: at });
+ return event;
+}
+
+const shiftDown = (at: number, init: KeyboardEventInit = {}) => keyEvent("keydown", { key: "Shift", code: "ShiftLeft", ...init }, at);
+const shiftUp = (at: number, init: KeyboardEventInit = {}) => keyEvent("keyup", { key: "Shift", code: "ShiftLeft", ...init }, at);
+const altDown = (at: number, init: KeyboardEventInit = {}) => keyEvent("keydown", { key: "Alt", code: "AltLeft", ...init }, at);
+const altUp = (at: number, init: KeyboardEventInit = {}) => keyEvent("keyup", { key: "Alt", code: "AltLeft", ...init }, at);
+
+describe("isModifierDoubleTapShortcut", () => {
+ it("accepts two identical taps of a known modifier", () => {
+ for (const modifier of ["Shift", "Alt", "Ctrl", "Meta", "Mod"]) {
+ expect(isModifierDoubleTapShortcut(`${modifier} ${modifier}`)).toBe(true);
+ }
+ });
+
+ it("rejects non-double-tap shapes", () => {
+ expect(isModifierDoubleTapShortcut("Shift")).toBe(false);
+ expect(isModifierDoubleTapShortcut("Shift Shift Shift")).toBe(false);
+ expect(isModifierDoubleTapShortcut("Shift Alt")).toBe(false);
+ expect(isModifierDoubleTapShortcut("Mod+P")).toBe(false);
+ expect(isModifierDoubleTapShortcut("")).toBe(false);
+ });
+});
+
+describe("matchesModifierDoubleTapShortcut", () => {
+ it("matches identical modifiers regardless of platform", () => {
+ expect(matchesModifierDoubleTapShortcut("Shift Shift", "Shift Shift", "Win32")).toBe(true);
+ expect(matchesModifierDoubleTapShortcut("Shift Shift", "Alt Alt", "Win32")).toBe(false);
+ });
+
+ it("resolves Mod to Meta on macOS and Ctrl elsewhere", () => {
+ expect(matchesModifierDoubleTapShortcut("Mod Mod", "Meta Meta", "MacIntel")).toBe(true);
+ expect(matchesModifierDoubleTapShortcut("Mod Mod", "Ctrl Ctrl", "MacIntel")).toBe(false);
+ expect(matchesModifierDoubleTapShortcut("Mod Mod", "Ctrl Ctrl", "Win32")).toBe(true);
+ expect(matchesModifierDoubleTapShortcut("Mod Mod", "Meta Meta", "Win32")).toBe(false);
+ });
+
+ it("never matches a double tap against a chord shortcut", () => {
+ expect(matchesModifierDoubleTapShortcut("Mod Mod", "Mod+P", "Win32")).toBe(false);
+ expect(matchesModifierDoubleTapShortcut("Alt Alt", "Mod+Alt+F", "MacIntel")).toBe(false);
+ });
+});
+
+describe("createModifierDoubleTapShortcutController", () => {
+ it("completes a double tap within the interval and reports the matched shortcut", () => {
+ const controller = createModifierDoubleTapShortcutController("Win32");
+ expect(controller.handleKeydown(shiftDown(100))).toBeUndefined();
+ expect(controller.handleKeyup(shiftUp(150))).toBeNull();
+ expect(controller.handleKeydown(shiftDown(300))).toBeUndefined();
+ expect(controller.handleKeyup(shiftUp(350))).toBe("Shift Shift");
+ });
+
+ it("re-anchors when the second tap starts outside the interval", () => {
+ const controller = createModifierDoubleTapShortcutController("Win32");
+ controller.handleKeydown(shiftDown(0));
+ expect(controller.handleKeyup(shiftUp(50))).toBeNull();
+ controller.handleKeydown(shiftDown(500));
+ expect(controller.handleKeyup(shiftUp(550))).toBeNull();
+ controller.handleKeydown(shiftDown(700));
+ expect(controller.handleKeyup(shiftUp(750))).toBe("Shift Shift");
+ });
+
+ it("cancels the pending first tap when a chord key intervenes", () => {
+ const controller = createModifierDoubleTapShortcutController("Win32");
+ controller.handleKeydown(shiftDown(0));
+ expect(controller.handleKeyup(shiftUp(50))).toBeNull();
+ controller.handleKeydown(keyEvent("keydown", { key: "a", code: "KeyA", shiftKey: true }, 100));
+ expect(controller.handleKeyup(keyEvent("keyup", { key: "a", code: "KeyA", shiftKey: true }, 150))).toBeNull();
+ controller.handleKeydown(shiftDown(200));
+ expect(controller.handleKeyup(shiftUp(250))).toBeNull();
+ controller.handleKeydown(shiftDown(400));
+ expect(controller.handleKeyup(shiftUp(450))).toBe("Shift Shift");
+ });
+
+ it("ignores auto-repeat keydowns", () => {
+ const controller = createModifierDoubleTapShortcutController("Win32");
+ controller.handleKeydown(shiftDown(0, { repeat: true }));
+ expect(controller.handleKeyup(shiftUp(50))).toBeNull();
+ controller.handleKeydown(shiftDown(100));
+ expect(controller.handleKeyup(shiftUp(150))).toBeNull();
+ controller.handleKeydown(shiftDown(300));
+ expect(controller.handleKeyup(shiftUp(350))).toBe("Shift Shift");
+ });
+
+ it("restarts the tap window when the second tap uses a different modifier", () => {
+ const controller = createModifierDoubleTapShortcutController("Win32");
+ controller.handleKeydown(shiftDown(0));
+ expect(controller.handleKeyup(shiftUp(50))).toBeNull();
+ controller.handleKeydown(altDown(100));
+ expect(controller.handleKeyup(altUp(150))).toBeNull();
+ controller.handleKeydown(altDown(300));
+ expect(controller.handleKeyup(altUp(350))).toBe("Alt Alt");
+ });
+
+ it("rejects a keyup that still holds another modifier", () => {
+ const controller = createModifierDoubleTapShortcutController("Win32");
+ controller.handleKeydown(shiftDown(0));
+ expect(controller.handleKeyup(shiftUp(50))).toBeNull();
+ controller.handleKeydown(shiftDown(200));
+ expect(controller.handleKeyup(shiftUp(250, { altKey: true }))).toBeNull();
+ });
+
+ it("purges keys whose keyup macOS swallowed during a Cmd chord and keeps recognizing taps", () => {
+ const controller = createModifierDoubleTapShortcutController("MacIntel");
+ controller.handleKeydown(keyEvent("keydown", { key: "Meta", code: "MetaLeft", metaKey: true }, 0));
+ controller.handleKeydown(keyEvent("keydown", { key: "a", code: "KeyA", metaKey: true }, 50));
+ expect(controller.handleKeyup(keyEvent("keyup", { key: "Meta", code: "MetaLeft" }, 100))).toBeNull();
+ controller.handleKeydown(shiftDown(200));
+ expect(controller.handleKeyup(shiftUp(250))).toBeNull();
+ controller.handleKeydown(shiftDown(400));
+ expect(controller.handleKeyup(shiftUp(450))).toBe("Shift Shift");
+ });
+
+ it("reset clears all pending tap and held-key state", () => {
+ const controller = createModifierDoubleTapShortcutController("Win32");
+ controller.handleKeydown(shiftDown(0));
+ expect(controller.handleKeyup(shiftUp(50))).toBeNull();
+ controller.reset();
+ controller.handleKeydown(shiftDown(200));
+ expect(controller.handleKeyup(shiftUp(250))).toBeNull();
+ controller.handleKeydown(shiftDown(400));
+ expect(controller.handleKeyup(shiftUp(450))).toBe("Shift Shift");
+ });
+});
diff --git a/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts b/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts
index 71abcdfe4a..1d7ef204a8 100644
--- a/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts
+++ b/apps/desktop/src/lib/__tests__/editor/shortcutRegistry.spec.ts
@@ -19,6 +19,7 @@ import {
shortcutToCodeMirrorKey,
toggleAiPanelDefaultShortcut,
type ShortcutActionId,
+ type ShortcutSettings,
} from "@/lib/editor/shortcutRegistry";
describe("shortcutRegistry editor actions", () => {
@@ -685,4 +686,29 @@ describe("shortcutRegistry editor actions", () => {
expect(countShortcutConflictPairs({ find: [] })).toBe(0);
});
});
+
+ describe("modifier double-tap shortcut conflicts", () => {
+ const settingsWith = (overrides: Partial<ShortcutSettings>): ShortcutSettings => ({ ...DEFAULT_SHORTCUT_SETTINGS, ...overrides });
+
+ it("treats Mod Mod and Meta Meta as the same double tap on macOS", () => {
+ const settings = settingsWith({ globalSearch: "Meta Meta" });
+ expect(findShortcutConflict("quickOpen", "Mod Mod", settings, "MacIntel")).toBe("globalSearch");
+ });
+
+ it("keeps Mod Mod and Meta Meta distinct on Windows", () => {
+ const settings = settingsWith({ globalSearch: "Meta Meta" });
+ expect(findShortcutConflict("quickOpen", "Mod Mod", settings, "Win32")).toBeNull();
+ });
+
+ it("matches Mod Mod with Ctrl Ctrl on Windows but not on macOS", () => {
+ const settings = settingsWith({ globalSearch: "Ctrl Ctrl" });
+ expect(findShortcutConflict("quickOpen", "Mod Mod", settings, "Win32")).toBe("globalSearch");
+ expect(findShortcutConflict("quickOpen", "Mod Mod", settings, "MacIntel")).toBeNull();
+ });
+
+ it("never conflicts a double tap with a chord shortcut", () => {
+ const settings = settingsWith({ globalSearch: "Mod+Alt+F" });
+ expect(findShortcutConflict("quickOpen", "Alt Alt", settings, "Win32")).toBeNull();
+ });
+ });
});
diff --git a/apps/desktop/src/lib/editor/modifierDoubleTapShortcut.ts b/apps/desktop/src/lib/editor/modifierDoubleTapShortcut.ts
new file mode 100644
index 0000000000..a654add361
--- /dev/null
+++ b/apps/desktop/src/lib/editor/modifierDoubleTapShortcut.ts
@@ -0,0 +1,96 @@
+import { isMacShortcutPlatform } from "@/lib/editor/shortcutDisplay";
+
+const modifiers = new Set(["Shift", "Alt", "Mod", "Ctrl", "Meta"]);
+
+export function isModifierDoubleTapShortcut(shortcut: string): boolean {
+ const parts = shortcut.split(" ");
+ return parts.length === 2 && parts[0] === parts[1] && modifiers.has(parts[0]!);
+}
+
+export function matchesModifierDoubleTapShortcut(first: string, second: string, platform = globalThis.navigator?.platform || ""): boolean {
+ if (!isModifierDoubleTapShortcut(first) || !isModifierDoubleTapShortcut(second)) return false;
+ const physicalModifier = (shortcut: string) => {
+ const modifier = shortcut.split(" ")[0];
+ return modifier === "Mod" ? (isMacShortcutPlatform(platform) ? "Meta" : "Ctrl") : modifier;
+ };
+ return physicalModifier(first) === physicalModifier(second);
+}
+
+function modifierName(key: string, platform: string): string | null {
+ if (key === "Shift" || key === "Alt") return key;
+ if (key === "Meta") return isMacShortcutPlatform(platform) ? "Mod" : "Meta";
+ if (key === "Control") return isMacShortcutPlatform(platform) ? "Ctrl" : "Mod";
+ return null;
+}
+
+/** Two complete, isolated taps of the same modifier. Normal key input is untouched. */
+export function createModifierDoubleTapShortcutController(platform = globalThis.navigator?.platform || "") {
+ const intervalMs = 400;
+ let pressedAt: number | null = null;
+ let pressedCode: string | null = null;
+ let pressedModifier: string | null = null;
+ let firstTapAt: number | null = null;
+ let firstTapModifier: string | null = null;
+ const heldKeys = new Set<string>();
+ const metaChordKeys = new Set<string>();
+
+ function cancel() {
+ pressedAt = null;
+ pressedCode = null;
+ pressedModifier = null;
+ firstTapAt = null;
+ firstTapModifier = null;
+ }
+
+ function reset() {
+ cancel();
+ heldKeys.clear();
+ metaChordKeys.clear();
+ }
+
+ function handleKeydown(event: KeyboardEvent) {
+ const code = event.code || event.key;
+ const alreadyHeld = heldKeys.has(code);
+ heldKeys.add(code);
+ const modifier = modifierName(event.key, platform);
+ if (isMacShortcutPlatform(platform) && event.metaKey && !modifier) metaChordKeys.add(code);
+ const otherModifier = (event.shiftKey && event.key !== "Shift") || (event.altKey && event.key !== "Alt") || (event.ctrlKey && event.key !== "Control") || (event.metaKey && event.key !== "Meta");
+ if (!modifier || alreadyHeld || heldKeys.size !== 1 || event.repeat || event.isComposing || otherModifier) {
+ cancel();
+ return;
+ }
+ if (firstTapAt !== null && (event.timeStamp - firstTapAt > intervalMs || modifier !== firstTapModifier)) cancel();
+ pressedAt = event.timeStamp;
+ pressedCode = code;
+ pressedModifier = modifier;
+ }
+
+ function handleKeyup(event: KeyboardEvent): string | null {
+ const code = event.code || event.key;
+ const wasHeld = heldKeys.delete(code);
+ metaChordKeys.delete(code);
+ // macOS may omit keyup for character keys pressed during a Cmd chord.
+ // The chord is not a tap, and must not leave future taps permanently blocked.
+ if (isMacShortcutPlatform(platform) && event.key === "Meta" && !event.metaKey && metaChordKeys.size) {
+ for (const key of metaChordKeys) heldKeys.delete(key);
+ metaChordKeys.clear();
+ cancel();
+ return null;
+ }
+ if (!wasHeld || heldKeys.size || event.isComposing || event.ctrlKey || event.metaKey || event.altKey || event.shiftKey || pressedAt === null || code !== pressedCode || event.timeStamp - pressedAt > intervalMs) {
+ cancel();
+ return null;
+ }
+ const modifier = pressedModifier!;
+ const completed = firstTapModifier === modifier && firstTapAt !== null && event.timeStamp - firstTapAt <= intervalMs;
+ const tapStartedAt = pressedAt;
+ cancel();
+ if (!completed) {
+ firstTapAt = tapStartedAt;
+ firstTapModifier = modifier;
+ }
+ return completed ? `${modifier} ${modifier}` : null;
+ }
+
+ return { handleKeydown, handleKeyup, cancel, reset };
+}
diff --git a/apps/desktop/src/lib/editor/shortcutRegistry.ts b/apps/desktop/src/lib/editor/shortcutRegistry.ts
index aa6e6c152c..9a44287ca8 100644
--- a/apps/desktop/src/lib/editor/shortcutRegistry.ts
+++ b/apps/desktop/src/lib/editor/shortcutRegistry.ts
@@ -1,4 +1,5 @@
import { isMacShortcutPlatform, parseShortcutParts, parseShortcutStrokes, shortcutDisplayParts } from "@/lib/editor/shortcutDisplay";
+import { isModifierDoubleTapShortcut, matchesModifierDoubleTapShortcut } from "@/lib/editor/modifierDoubleTapShortcut";
export type ShortcutActionId =
| "executeSql"
@@ -100,6 +101,7 @@ export interface ShortcutDefinition {
scope: ShortcutScope;
defaultShortcut: string;
inputKind?: "keyboard" | "modifier-only";
+ supportsModifierDoubleTap?: boolean;
}
export type ShortcutSettings = Record<ShortcutActionId, string>;
@@ -489,12 +491,14 @@ export const SHORTCUT_DEFINITIONS: ShortcutDefinition[] = [
},
{
id: "quickOpen",
+ supportsModifierDoubleTap: true,
labelKey: "settings.shortcutQuickOpen",
scope: "global",
defaultShortcut: "Mod+P",
},
{
id: "globalSearch",
+ supportsModifierDoubleTap: true,
labelKey: "settings.shortcutGlobalSearch",
scope: "global",
defaultShortcut: "Mod+Alt+F",
@@ -733,6 +737,7 @@ function hasExplicitShortcut(settings: Partial<ShortcutSettings> | undefined, ac
}
function shortcutsUseSameKeys(first: string, second: string, platform = globalThis.navigator?.platform || ""): boolean {
+ if (isModifierDoubleTapShortcut(first) || isModifierDoubleTapShortcut(second)) return matchesModifierDoubleTapShortcut(first, second, platform);
const comparisonKey = (shortcut: string) =>
formatShortcut(shortcut, platform)
.trim()