feat(editor): add SQL editor context menu shortcuts

* feat(editor): add SQL editor context menu shortcuts

* chore(i18n): autofill new translations

---------

Co-authored-by: faithererer <faithererer@users.noreply.github.com>
Co-authored-by: dbx-i18n-bot <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-07-05 19:38:51 +08:00
1 parent d502b4ce6c
commit 8b035d0989
17 files changed
+207 -108

No files matched your search

@@ -0,0 +1,22 @@
import { describe, expect, it } from "vitest";
import { formatShortcutDisplay, shortcutDisplayKeys } from "@/lib/editor/shortcutDisplay";
describe("shortcut display", () => {
it("uses readable modifier labels on Windows", () => {
expect(shortcutDisplayKeys("Shift+Alt+U", "Win32")).toEqual(["Shift", "Alt", "U"]);
});
it("uses readable modifier labels on Linux", () => {
expect(shortcutDisplayKeys("Ctrl+Alt+Delete", "Linux x86_64")).toEqual(["Ctrl", "Alt", "Del"]);
});
it("uses Apple platform glyphs on macOS", () => {
expect(shortcutDisplayKeys("Mod+Alt+Enter", "MacIntel")).toEqual(["⌘", "⌥", "↵"]);
});
it("formats shortcut pills with platform separators", () => {
expect(formatShortcutDisplay("Shift+Alt+ArrowUp", "Win32")).toBe("Shift + Alt + ↑");
expect(formatShortcutDisplay("Shift+Alt+ArrowUp", "MacIntel")).toBe("⇧ ⌥ ↑");
expect(formatShortcutDisplay("Mod+Delete", "MacIntel")).toBe("⌘ ⌦");
});
});
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
import { DEFAULT_SHORTCUT_SETTINGS, SHORTCUT_DEFINITIONS, findShortcutConflict, normalizeShortcutSettings, type ShortcutActionId } from "@/lib/editor/shortcutRegistry";
describe("shortcutRegistry editor actions", () => {
const formatterEditorActionIds: ShortcutActionId[] = ["formatSql", "indentMore", "indentLess", "duplicateLine", "deleteLine", "moveLineUp", "moveLineDown", "copyLineUp", "copyLineDown", "undo", "redo", "selectAll"];
const formatterEditorActionIds: ShortcutActionId[] = ["formatSql", "indentMore", "indentLess", "duplicateLine", "deleteLine", "moveLineUp", "moveLineDown", "copyLineUp", "copyLineDown", "undo", "redo", "selectAll", "uppercaseSelection", "lowercaseSelection"];
const sidebarShortcutActionIds: ShortcutActionId[] = ["copySidebarSelection", "pasteSidebarSelection", "editSidebarConnection"];
it("registers formatter editor shortcuts in the generic editor scope", () => {
@@ -30,6 +30,8 @@ describe("shortcutRegistry editor actions", () => {
expect(shortcuts.undo).toBe("Mod+Z");
expect(shortcuts.redo).toBe("Shift+Mod+Z");
expect(shortcuts.selectAll).toBe("Mod+A");
expect(shortcuts.uppercaseSelection).toBe("Shift+Alt+U");
expect(shortcuts.lowercaseSelection).toBe("Shift+Alt+L");
});
it("detects conflicts between formatter editor shortcuts and other editor shortcuts", () => {
@@ -38,6 +40,12 @@ describe("shortcutRegistry editor actions", () => {
expect(findShortcutConflict("duplicateLine", shortcuts.duplicateLine, shortcuts)).toBe("find");
});
it("detects conflicts for SQL selection case shortcuts", () => {
const shortcuts = normalizeShortcutSettings({ uppercaseSelection: "Mod+A" });
expect(findShortcutConflict("uppercaseSelection", shortcuts.uppercaseSelection, shortcuts)).toBe("selectAll");
});
it("registers sidebar shortcuts in the sidebar scope", () => {
for (const actionId of sidebarShortcutActionIds) {
const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === actionId);
@@ -0,0 +1,37 @@
export function isMacShortcutPlatform(platform = globalThis.navigator?.platform || ""): boolean {
return platform.toLowerCase().includes("mac");
}
export function shortcutKeyLabel(part: string, platform = globalThis.navigator?.platform || ""): string {
const isMac = isMacShortcutPlatform(platform);
if (part === "Mod") return isMac ? "⌘" : "Ctrl";
if (part === "Cmd") return isMac ? "⌘" : "Cmd";
if (part === "Meta") return isMac ? "⌘" : "Meta";
if (part === "Alt") return isMac ? "⌥" : "Alt";
if (part === "Shift") return isMac ? "⇧" : "Shift";
if (part === "Control" || part === "Ctrl") return isMac ? "⌃" : "Ctrl";
if (part === "Delete") return isMac ? "⌦" : "Del";
if (part === "Backspace") return "⌫";
if (part === "Enter") return "↵";
if (part === "Escape") return "Esc";
if (part === "ArrowUp") return "↑";
if (part === "ArrowDown") return "↓";
if (part === "ArrowLeft") return "←";
if (part === "ArrowRight") return "→";
if (part === " ") return "Space";
return part.length === 1 ? part.toUpperCase() : part;
}
export function shortcutDisplayKeys(shortcut?: string, platform = globalThis.navigator?.platform || ""): string[] {
return (
shortcut
?.split("+")
.filter(Boolean)
.map((part) => shortcutKeyLabel(part, platform)) || []
);
}
export function formatShortcutDisplay(shortcut: string, platform = globalThis.navigator?.platform || ""): string {
if (!shortcut) return "—";
return shortcutDisplayKeys(shortcut, platform).join(isMacShortcutPlatform(platform) ? " " : " + ");
}
@@ -14,6 +14,8 @@ export type ShortcutActionId =
| "undo"
| "redo"
| "selectAll"
| "uppercaseSelection"
| "lowercaseSelection"
| "copyCurrentRow"
| "deleteCurrentRow"
| "newQuery"
@@ -147,6 +149,18 @@ export const SHORTCUT_DEFINITIONS: ShortcutDefinition[] = [
scope: "editor",
defaultShortcut: "Mod+A",
},
{
id: "uppercaseSelection",
labelKey: "settings.shortcutUppercaseSelection",
scope: "editor",
defaultShortcut: "Shift+Alt+U",
},
{
id: "lowercaseSelection",
labelKey: "settings.shortcutLowercaseSelection",
scope: "editor",
defaultShortcut: "Shift+Alt+L",
},
{
id: "copyCurrentRow",
labelKey: "settings.shortcutCopyCurrentRow",