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(settings): let Ctrl+S apply the settings draft on the settings page (#13048)
弈秋0eb234709952
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vueindex aa29029a82..900945a2f6 100644--- a/apps/desktop/src/App.vue+++ b/apps/desktop/src/App.vue@@ -168,6 +168,7 @@ import {isToggleZenModeShortcut,isZoomInShortcut,isZoomOutShortcut,+ saveShortcutSurface,switchToTabIndexFromShortcut,tabSwitcherDirectionFromShortcut,} from "@/lib/editor/keyboardShortcuts";@@ -4782,11 +4783,30 @@ async function handleKeydown(e: KeyboardEvent) {if (isSaveShortcut(e, shortcuts) && e.target instanceof Element && isObjectSourceSaveShortcutTarget(e.target)) {return;}- if (activeTab.value?.mode === "query" && !showSaveSqlDialog.value && isSaveShortcut(e, shortcuts)) {- e.preventDefault();- e.stopPropagation();- void openSaveSqlDialog();- return;+ if (isSaveShortcut(e, shortcuts)) {+ // The settings page, plugin center and driver store keep the previously active+ // query tab activated, so the active tab alone cannot decide who Ctrl+S belongs+ // to. Without the surface check the shortcut popped the save-SQL dialog on top of+ // the settings page and silently dropped the edited draft (#13020).+ const saveShortcutTarget = saveShortcutSurface({+ settingsPageOpen: showSettingsPage.value,+ pluginCenterOpen: showPluginCenter.value,+ driverStoreOpen: showDriverStore.value,+ activeTabMode: activeTab.value?.mode ?? null,+ saveSqlDialogOpen: showSaveSqlDialog.value,+ });+ if (saveShortcutTarget === "settings") {+ e.preventDefault();+ e.stopPropagation();+ void settingsPageRef.value?.applySettingsFromShortcut();+ return;+ }+ if (saveShortcutTarget === "query") {+ e.preventDefault();+ e.stopPropagation();+ void openSaveSqlDialog();+ return;+ }}// CodeMirror ignores keydown events after an IME composition changes the// document, so this app-level fallback must share the editor shortcut guard.diff --git a/apps/desktop/src/components/editor/EditorSettingsDialog.vue b/apps/desktop/src/components/editor/EditorSettingsDialog.vueindex 3c1b35f455..17f296526c 100644--- a/apps/desktop/src/components/editor/EditorSettingsDialog.vue+++ b/apps/desktop/src/components/editor/EditorSettingsDialog.vue@@ -648,7 +648,7 @@ function closeSettings() {requestCloseSettings(false);}-defineExpose({ requestClose: closeSettings });+defineExpose({ requestClose: closeSettings, applySettingsFromShortcut });function cancelUnsavedSettingsClose() {showUnsavedSettingsCloseConfirm.value = false;@@ -2597,6 +2597,15 @@ async function applySettingsAndClose() {}}+// Ctrl+S on the settings page behaves like the "Apply" button: persist the draft+// but stay open (the shortcut means "save", not "save and quit"). Mirrors the+// button's own disabled state so a key press cannot bypass an apply blocker, and+// never fires when there is nothing to persist.+async function applySettingsFromShortcut() {+ if (!hasChanges()) return;+ await applySettings();+}+async function restartDbxForDuckDbIsolation() {if (duckDbRestarting.value || hasApplyBlocker.value || isWeb) return;duckDbRestarting.value = true;diff --git a/apps/desktop/src/components/editor/__tests__/EditorSettingsDialog.saveShortcut.integration.spec.ts b/apps/desktop/src/components/editor/__tests__/EditorSettingsDialog.saveShortcut.integration.spec.tsnew file mode 100644index 0000000000..9c320ca735--- /dev/null+++ b/apps/desktop/src/components/editor/__tests__/EditorSettingsDialog.saveShortcut.integration.spec.ts@@ -0,0 +1,125 @@+// @vitest-environment happy-dom++import { createApp, defineComponent, h, nextTick, ref, type App } from "vue";+import { createPinia, setActivePinia } from "pinia";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import i18n from "@/i18n";+import { useSettingsStore } from "@/stores/settingsStore";+import EditorSettingsDialog from "../EditorSettingsDialog.vue";++const backend = vi.hoisted(() => ({ saved: null as unknown, saves: vi.fn() }));++vi.mock("@/lib/backend/api", async (importOriginal) => {+ const actual = await importOriginal<typeof import("@/lib/backend/api")>();+ return {+ ...actual,+ loadEditorSettings: async () => backend.saved,+ saveEditorSettings: async (value: unknown) => {+ backend.saved = structuredClone(value);+ backend.saves(value);+ },+ loadHistoryRetentionLimit: async () => 5000,+ loadMcpHistoryRetentionLimit: async () => 5000,+ loadMcpGlobalPolicy: async () => null,+ loadDesktopSettings: async () => null,+ loadAiConfigs: async () => [],+ loadAiConfig: async () => null,+ loadAiProviderConfigs: async () => ({}),+ loadAiChatSelection: async () => null,+ webdavSyncSecretsStatus: async () => ({}),+ snippetSavedTokenStatus: async () => ({}),+ snippetSyncSettings: async () => ({}),+ };+});++let app: App | undefined;+let host: HTMLElement;++async function settle() {+ for (let i = 0; i < 10; i++) {+ await Promise.resolve();+ await nextTick();+ }+}++beforeEach(() => {+ backend.saved = null;+ backend.saves.mockClear();+ localStorage.clear();+});++afterEach(() => {+ app?.unmount();+ host?.remove();+ document.body.innerHTML = "";+});++async function mountPage() {+ const pinia = createPinia();+ setActivePinia(pinia);+ const store = useSettingsStore();+ await store.initEditorSettings();+ await store.initDesktopSettings();+ backend.saves.mockClear();+ const page = ref<{ requestClose(): void; applySettingsFromShortcut(): Promise<void> } | null>(null);+ const open = ref(true);+ host = document.createElement("div");+ document.body.append(host);+ app = createApp(+ defineComponent({+ setup: () => () =>+ open.value+ ? h(EditorSettingsDialog, {+ ref: page,+ variant: "page",+ open: true,+ initialTab: "editor",+ "onUpdate:open": (value: boolean) => {+ open.value = value;+ },+ })+ : null,+ }),+ );+ app.use(pinia);+ app.use(i18n);+ app.mount(host);+ await settle();+ const changeFontSize = async () => {+ const input = host.querySelector<HTMLInputElement>('input[type="range"][min="10"][max="24"]')!;+ input.value = "19";+ input.dispatchEvent(new Event("input", { bubbles: true }));+ await settle();+ };+ return { page, open, store, changeFontSize };+}++describe("Ctrl+S on the settings page (exposed apply entrypoint)", () => {+ // The shortcut means "save", not "save and quit": App.vue routes Ctrl+S here+ // while the settings page owns the window, so a dirty draft must be persisted+ // without closing the page (#13020).+ it("persists a dirty draft without closing the page", async () => {+ const { page, open, store, changeFontSize } = await mountPage();+ const originalFontSize = store.editorSettings.fontSize;+ expect(originalFontSize).not.toBe(19);+ await changeFontSize();++ await page.value!.applySettingsFromShortcut();+ await settle();++ expect(store.editorSettings.fontSize).toBe(19);+ expect(backend.saves).toHaveBeenCalled();+ expect(open.value).toBe(true);+ expect(host.querySelector<HTMLInputElement>('input[type="range"][min="10"][max="24"]')?.value).toBe("19");+ });++ it("does nothing at all when there is no draft change", async () => {+ const { page, open } = await mountPage();++ await page.value!.applySettingsFromShortcut();+ await settle();++ expect(backend.saves).not.toHaveBeenCalled();+ expect(open.value).toBe(true);+ });+});diff --git a/apps/desktop/src/lib/__tests__/editor/keyboardShortcuts.spec.ts b/apps/desktop/src/lib/__tests__/editor/keyboardShortcuts.spec.tsindex a5ba0cd9f4..ffc845646e 100644--- a/apps/desktop/src/lib/__tests__/editor/keyboardShortcuts.spec.ts+++ b/apps/desktop/src/lib/__tests__/editor/keyboardShortcuts.spec.ts@@ -28,6 +28,7 @@ import {isToggleAiPanelShortcut,matchesModifierOnlyShortcut,matchesShortcut,+ saveShortcutSurface,tabSwitcherDirectionFromShortcut,} from "@/lib/editor/keyboardShortcuts";import { formatShortcutDisplay, isMacShortcutPlatform } from "@/lib/editor/shortcutDisplay";@@ -399,3 +400,35 @@ describe("shouldBlockCaretBrowsing", () => {expect(shouldBlockCaretBrowsing({ key: "F7" }, { caretBrowsingEnabled: false, shortcuts: { executeSql: "Ctrl+Enter" } })).toBe(true);});});++describe("saveShortcutSurface", () => {+ it("applies the settings draft while the settings page owns the window", () => {+ expect(saveShortcutSurface({ settingsPageOpen: true, activeTabMode: "query" })).toBe("settings");+ });++ it("keeps sending Ctrl+S to the save-SQL dialog for an active query tab", () => {+ expect(saveShortcutSurface({ activeTabMode: "query" })).toBe("query");+ });++ it("stays out of the query branch while the save-SQL dialog is already open", () => {+ expect(saveShortcutSurface({ activeTabMode: "query", saveSqlDialogOpen: true })).toBe("none");+ });++ it("does nothing for a non-query tab", () => {+ expect(saveShortcutSurface({ activeTabMode: "table" })).toBe("none");+ expect(saveShortcutSurface({ activeTabMode: null })).toBe("none");+ expect(saveShortcutSurface({})).toBe("none");+ });++ // The plugin center and driver store also replace the content area while the+ // previously active query tab stays active, so the active tab alone used to+ // send Ctrl+S down the save-SQL branch (#13020).+ it("does nothing while the plugin center or driver store is open", () => {+ expect(saveShortcutSurface({ pluginCenterOpen: true, activeTabMode: "query" })).toBe("none");+ expect(saveShortcutSurface({ driverStoreOpen: true, activeTabMode: "query" })).toBe("none");+ });++ it("prefers the settings page over the other browsing surfaces", () => {+ expect(saveShortcutSurface({ settingsPageOpen: true, pluginCenterOpen: true, driverStoreOpen: true, activeTabMode: "query" })).toBe("settings");+ });+});diff --git a/apps/desktop/src/lib/editor/keyboardShortcuts.ts b/apps/desktop/src/lib/editor/keyboardShortcuts.tsindex 9ad75839e4..98490bfd86 100644--- a/apps/desktop/src/lib/editor/keyboardShortcuts.ts+++ b/apps/desktop/src/lib/editor/keyboardShortcuts.ts@@ -294,6 +294,34 @@ export function isObjectSourceSaveShortcutTarget(target: { closest(selector: strreturn !!target?.closest("[data-object-source-editor], [data-object-source-preview]");}+/**+ * Which surface the "save" shortcut should act on.+ *+ * The settings page, plugin center and driver store replace the content area but+ * keep the previously active query tab activated, so `activeTab.mode === "query"`+ * stays true while one of those surfaces is on screen. Without this decision the+ * save shortcut popped the "SQL saved" dialog on top of the settings page instead+ * of applying the edited draft (#13020).+ */+export type SaveShortcutSurface = "settings" | "query" | "none";++export interface SaveShortcutSurfaceInput {+ settingsPageOpen?: boolean;+ pluginCenterOpen?: boolean;+ driverStoreOpen?: boolean;+ activeTabMode?: string | null;+ saveSqlDialogOpen?: boolean;+}++export function saveShortcutSurface(input: SaveShortcutSurfaceInput): SaveShortcutSurface {+ if (input.settingsPageOpen) return "settings";+ // Browsing surfaces have nothing to save, and must not fall through to the+ // query branch just because a query tab is still the active tab.+ if (input.pluginCenterOpen || input.driverStoreOpen) return "none";+ if (input.activeTabMode !== "query" || input.saveSqlDialogOpen) return "none";+ return "query";+}+export function isCopyCurrentRowShortcut(event: ShortcutLikeEvent, shortcuts?: Partial<ShortcutSettings>): boolean {return matchesShortcut(event, actionShortcut("copyCurrentRow", shortcuts));}