feat(grid): add configurable shortcut to focus WHERE condition

This commit is contained in:
关关 authored and GitHub committed 2026-09-30 01:20:31 +08:00
1 parent 530bb2bb52
commit 7bc85dfcb0
27 files changed
+325

No files matched your search

@@ -6,6 +6,7 @@ import {
isEditTableStructureShortcut,
isExecuteSqlInNewResultTabShortcut,
isGoToColumnShortcut,
isFocusWhereShortcut,
isGoToFirstPageShortcut,
isGoToLastPageShortcut,
isGoToNextPageShortcut,
@@ -20,6 +21,14 @@ import { formatShortcutDisplay, isMacShortcutPlatform } from "@/lib/editor/short
import { shortcutToCodeMirrorKey } from "@/lib/editor/shortcutRegistry";
describe("keyboard shortcut matching", () => {
it("matches configured WHERE focus on macOS and Windows while respecting a cleared binding", () => {
expect(isFocusWhereShortcut({ key: "L", metaKey: true, shiftKey: true }, { focusWhere: "Mod+Shift+L" }, "MacIntel")).toBe(true);
expect(isFocusWhereShortcut({ key: "L", ctrlKey: true, shiftKey: true }, { focusWhere: "Mod+Shift+L" }, "Win32")).toBe(true);
expect(isFocusWhereShortcut({ key: "L", ctrlKey: true, shiftKey: true }, { focusWhere: "" }, "Win32")).toBe(false);
expect(isFocusWhereShortcut({ key: "L", ctrlKey: true, shiftKey: true }, undefined, "Win32")).toBe(false);
expect(isFocusWhereShortcut({ key: "L", metaKey: true, shiftKey: true }, undefined, "MacIntel")).toBe(false);
});
it("records modifier-only mouse shortcut settings", () => {
expect(eventToModifierOnlyShortcut({ key: "Alt", altKey: true })).toBe("Alt");
expect(eventToModifierOnlyShortcut({ key: "Shift", shiftKey: true })).toBe("Shift");
@@ -82,6 +82,16 @@ describe("shortcutRegistry editor actions", () => {
expect(findShortcutConflict("goToFirstPage", "Mod+F", shortcuts)).toBeNull();
});
it("leaves focus-WHERE unassigned for new and existing settings and detects grid conflicts", () => {
expect(DEFAULT_SHORTCUT_SETTINGS.focusWhere).toBe("");
expect(normalizeShortcutSettings().focusWhere).toBe("");
expect(normalizeShortcutSettings({ executeSql: "Mod+Enter" }).focusWhere).toBe("");
expect(normalizeShortcutSettings({ focusWhere: "" }).focusWhere).toBe("");
const shortcuts = normalizeShortcutSettings({ focusWhere: "Mod+D" });
expect(shortcuts.focusWhere).toBe("Mod+D");
expect(findShortcutConflict("focusWhere", shortcuts.focusWhere, shortcuts)).toBe("copyCurrentRow");
});
it("registers go to column as an unassigned grid shortcut", () => {
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === "goToColumn");
@@ -273,6 +273,10 @@ export function isDeleteCurrentRowShortcut(event: ShortcutLikeEvent, shortcuts?:
return matchesShortcut(event, actionShortcut("deleteCurrentRow", shortcuts));
}
export function isFocusWhereShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>, platform = globalThis.navigator?.platform || ""): boolean {
return matchesShortcut(event, actionShortcut("focusWhere", shortcuts, platform), platform);
}
export function isGoToColumnShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>, platform = globalThis.navigator?.platform || ""): boolean {
return matchesShortcut(event, actionShortcut("goToColumn", shortcuts, platform), platform);
}
@@ -35,6 +35,7 @@ export type ShortcutActionId =
| "editTableStructure"
| "copyCurrentRow"
| "deleteCurrentRow"
| "focusWhere"
| "goToColumn"
| "goToFirstPage"
| "goToPreviousPage"
@@ -355,6 +356,12 @@ export const SHORTCUT_DEFINITIONS: ShortcutDefinition[] = [
scope: "grid",
defaultShortcut: "Delete",
},
{
id: "focusWhere",
labelKey: "settings.shortcutFocusWhere",
scope: "grid",
defaultShortcut: "",
},
{
id: "goToColumn",
labelKey: "settings.shortcutGoToColumn",