feat(shortcuts): suppress Shift+Esc browser task manager

This commit is contained in:
lxk955 authored and GitHub committed 2026-10-03 21:57:22 +08:00
1 parent b498b1e63a
commit 37d5ea0bd4
4 files changed
+49 -1

No files matched your search

+12 -1
View File
@@ -106,6 +106,7 @@ import { activeDesktopAiRuns, blockingDesktopAiRunsForQuit } from "@/lib/ai/desk
import { import {
isBrowserReloadShortcut, isBrowserReloadShortcut,
isBrowserTaskManagerShortcut,
isCloseOtherTabsShortcut, isCloseOtherTabsShortcut,
isCloseTabShortcut, isCloseTabShortcut,
isExecuteSqlInNewResultTabShortcut, isExecuteSqlInNewResultTabShortcut,
@@ -3707,6 +3708,11 @@ const tabSwitcherKeyboard = createTabSwitcherKeyboardController({
}); });
function handleNativeSelectAll(e: KeyboardEvent) { function handleNativeSelectAll(e: KeyboardEvent) {
if (isBrowserTaskManagerShortcut(e)) {
e.preventDefault();
e.stopPropagation();
return;
}
if (shouldBlockAppNativeSelectAll(e)) e.preventDefault(); if (shouldBlockAppNativeSelectAll(e)) e.preventDefault();
} }
@@ -4000,6 +4006,11 @@ async function handleKeydown(e: KeyboardEvent) {
return; return;
} }
} }
if (isBrowserTaskManagerShortcut(e)) {
e.preventDefault();
e.stopPropagation();
return;
}
if (isDesktop && isBrowserReloadShortcut(e)) { if (isDesktop && isBrowserReloadShortcut(e)) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
@@ -4174,6 +4185,7 @@ watch(appReady, (ready) => void syncConnectionLivenessSubscription(ready), { imm
onMounted(async () => { onMounted(async () => {
clearStartupPreloadRetry(); clearStartupPreloadRetry();
markStartupPhase("app-mounted"); markStartupPhase("app-mounted");
window.addEventListener("keydown", handleNativeSelectAll, true);
console.log("[STARTUP] onMounted begin"); console.log("[STARTUP] onMounted begin");
const mountStart = performance.now(); const mountStart = performance.now();
if (isDetachedWindowContext) { if (isDetachedWindowContext) {
@@ -4195,7 +4207,6 @@ onMounted(async () => {
}); });
applyTheme(); applyTheme();
void applyUiScale(settingsStore.editorSettings.uiScale); void applyUiScale(settingsStore.editorSettings.uiScale);
window.addEventListener("keydown", handleNativeSelectAll, true);
window.addEventListener("keydown", handleGlobalSearchKeydownCapture, true); window.addEventListener("keydown", handleGlobalSearchKeydownCapture, true);
window.addEventListener("keydown", handleTabSwitcherKeydownCapture, true); window.addEventListener("keydown", handleTabSwitcherKeydownCapture, true);
window.addEventListener("keydown", handleAuxiliarySearchKeydownCapture, true); window.addEventListener("keydown", handleAuxiliarySearchKeydownCapture, true);
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import { import {
eventToModifierOnlyShortcut, eventToModifierOnlyShortcut,
eventToShortcut, eventToShortcut,
isBrowserTaskManagerShortcut,
isConvertNamingStyleShortcut, isConvertNamingStyleShortcut,
isEditTableStructureShortcut, isEditTableStructureShortcut,
isExecuteSqlInNewResultTabShortcut, isExecuteSqlInNewResultTabShortcut,
@@ -264,3 +265,19 @@ describe("tabSwitcherDirectionFromShortcut", () => {
expect(tabSwitcherDirectionFromShortcut({ key: "Tab", ctrlKey: true }, { tabSwitcher: "Shift+Ctrl+Tab" })).toBeNull(); expect(tabSwitcherDirectionFromShortcut({ key: "Tab", ctrlKey: true }, { tabSwitcher: "Shift+Ctrl+Tab" })).toBeNull();
}); });
}); });
describe("isBrowserTaskManagerShortcut", () => {
it("matches Shift+Escape combinations and rejects regular Escape or extra modifiers", () => {
expect(isBrowserTaskManagerShortcut({ key: "Escape", shiftKey: true })).toBe(true);
expect(isBrowserTaskManagerShortcut({ key: "Esc", shiftKey: true })).toBe(true);
expect(isBrowserTaskManagerShortcut({ code: "Escape", shiftKey: true, key: "Unidentified" })).toBe(true);
expect(isBrowserTaskManagerShortcut({ key: "Escape" })).toBe(false);
expect(isBrowserTaskManagerShortcut({ key: "Escape", shiftKey: false })).toBe(false);
expect(isBrowserTaskManagerShortcut({ key: "Escape", shiftKey: true, ctrlKey: true })).toBe(false);
expect(isBrowserTaskManagerShortcut({ key: "Escape", shiftKey: true, metaKey: true })).toBe(false);
expect(isBrowserTaskManagerShortcut({ key: "Escape", shiftKey: true, altKey: true })).toBe(false);
expect(isBrowserTaskManagerShortcut({ key: "Escape", shiftKey: true, isComposing: true })).toBe(false);
expect(isBrowserTaskManagerShortcut({ key: "x", shiftKey: true })).toBe(false);
});
});
@@ -383,3 +383,9 @@ export function isBrowserReloadShortcut(event: ShortcutLikeEvent): boolean {
if (key === "F5") return true; if (key === "F5") return true;
return key === "r" && (!!event.metaKey || !!event.ctrlKey); return key === "r" && (!!event.metaKey || !!event.ctrlKey);
} }
export function isBrowserTaskManagerShortcut(event: ShortcutLikeEvent): boolean {
if (event.isComposing || event.altKey || event.ctrlKey || event.metaKey) return false;
if (!event.shiftKey) return false;
return event.key === "Escape" || event.key === "Esc" || event.code === "Escape";
}
+14
View File
@@ -4,6 +4,7 @@ import {
eventToShortcut, eventToShortcut,
handleTabHistoryNavigationShortcut, handleTabHistoryNavigationShortcut,
isBrowserReloadShortcut, isBrowserReloadShortcut,
isBrowserTaskManagerShortcut,
isCancelSearchShortcut, isCancelSearchShortcut,
isCloseOtherTabsShortcut, isCloseOtherTabsShortcut,
isCloseTabShortcut, isCloseTabShortcut,
@@ -368,6 +369,19 @@ test("detects browser reload shortcuts for desktop suppression", () => {
assert.equal(isBrowserReloadShortcut({ key: "r", ctrlKey: true, isComposing: true }), false); assert.equal(isBrowserReloadShortcut({ key: "r", ctrlKey: true, isComposing: true }), false);
}); });
test("detects browser task manager shortcut (Shift+Escape) for suppression", () => {
assert.equal(isBrowserTaskManagerShortcut({ key: "Escape", shiftKey: true }), true);
assert.equal(isBrowserTaskManagerShortcut({ key: "Esc", shiftKey: true }), true);
assert.equal(isBrowserTaskManagerShortcut({ code: "Escape", shiftKey: true, key: "Unidentified" }), true);
assert.equal(isBrowserTaskManagerShortcut({ key: "Escape" }), false);
assert.equal(isBrowserTaskManagerShortcut({ key: "Escape", shiftKey: false }), false);
assert.equal(isBrowserTaskManagerShortcut({ key: "Escape", shiftKey: true, ctrlKey: true }), false);
assert.equal(isBrowserTaskManagerShortcut({ key: "Escape", shiftKey: true, metaKey: true }), false);
assert.equal(isBrowserTaskManagerShortcut({ key: "Escape", shiftKey: true, altKey: true }), false);
assert.equal(isBrowserTaskManagerShortcut({ key: "Escape", shiftKey: true, isComposing: true }), false);
assert.equal(isBrowserTaskManagerShortcut({ key: "Tab", shiftKey: true }), false);
});
test("matches Mod-R without shift or alt for scoped refresh and replace", () => { test("matches Mod-R without shift or alt for scoped refresh and replace", () => {
assert.equal(isModRShortcut({ key: "r", ctrlKey: true }), true); assert.equal(isModRShortcut({ key: "r", ctrlKey: true }), true);
assert.equal(isModRShortcut({ key: "R", metaKey: true }), true); assert.equal(isModRShortcut({ key: "R", metaKey: true }), true);