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。

fix(grid): save value editor and cell detail edits via Ctrl+S

kuangzhiqiangb41538ba6b61
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index 080b898f2a..ba36b3eb92 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -6308,6 +6308,19 @@ watch(valueEditorContainer, async (el) => {
onBlur: () => {
if (!detailValueDiffOpen.value && !detailTransformOpen.value) commitValueEditorEdit();
},
+ // 非 temporal 值编辑器(CodeMirror)里按 Ctrl/Cmd+S:仅靠网格全局快捷键不会把
+ // 草稿提交成待保存变更,必须在这里认领保存键——先 commitValueEditorEdit 落脏,
+ // 再触发保存(#10515;temporal 走 @save→onTemporalCellEditorSave)。
+ // useCellDetailEditor 对每个 keydown 都会回调本钩子,必须先用 isSaveShortcut
+ // 过滤:否则普通按键也被吞掉(preventDefault),编辑器将完全无法输入。
+ onSaveShortcut: (event) => {
+ if (!isSaveShortcut(event, settingsStore.editorSettings.shortcuts)) return false;
+ commitValueEditorEdit();
+ void nextTick().then(() => {
+ void saveGridChangesFromShortcut();
+ });
+ return true;
+ },
editorTheme: editorThemeAccessor,
appAppearance: editorAppAppearance,
appPalette: editorAppPalette,
diff --git a/apps/desktop/src/components/grid/DataGridCellDetailPanel.vue b/apps/desktop/src/components/grid/DataGridCellDetailPanel.vue
index 43038b851d..c93a29e72a 100644
--- a/apps/desktop/src/components/grid/DataGridCellDetailPanel.vue
+++ b/apps/desktop/src/components/grid/DataGridCellDetailPanel.vue
@@ -60,7 +60,17 @@ const emit = defineEmits<{
copySqlCondition: [];
}>();
-const { geometryPreviewOpen, geometryCanvas, detailsEditorContainer, sideJsonPreviewContainer, openSearch } = useDataGridCellDetail({ detail: toRef(props, "detail"), editValue: detailEditValue, onCancel: () => emit("cancel") });
+const { geometryPreviewOpen, geometryCanvas, detailsEditorContainer, sideJsonPreviewContainer, openSearch } = useDataGridCellDetail({
+ detail: toRef(props, "detail"),
+ editValue: detailEditValue,
+ onCancel: () => emit("cancel"),
+ // 详情编辑器里按 Ctrl/Cmd+S 与 temporal 编辑器的 ctrl+s 路径保持一致:
+ // 先 emit commit(把草稿落成待保存变更),再 emit save(触发网格保存)。
+ onSave: () => {
+ emit("commit");
+ emit("save");
+ },
+});
void geometryCanvas;
void detailsEditorContainer;
void sideJsonPreviewContainer;
diff --git a/apps/desktop/src/components/grid/TemporalCellEditor.vue b/apps/desktop/src/components/grid/TemporalCellEditor.vue
index ec17ff472d..9f6d44ea74 100644
--- a/apps/desktop/src/components/grid/TemporalCellEditor.vue
+++ b/apps/desktop/src/components/grid/TemporalCellEditor.vue
@@ -211,6 +211,12 @@ function finishCommit() {
closeHandled = true;
isCommitting = true;
emit("commit");
+ // 值编辑器面板用 commitValueEditorEdit 保持同一实例不卸载(以便连续编辑),
+ // isCommitting 若一直闩锁,第二次 ctrl+s/Enter 会在上面的短路处被吞掉(#10515)。
+ // 本 tick 内仍防重入;下一个微任务复位,让持续挂载的实例可再次提交。
+ nextTick(() => {
+ isCommitting = false;
+ });
}
function finishCancel() {
@@ -218,6 +224,9 @@ function finishCancel() {
closeHandled = true;
isCommitting = true;
emit("cancel");
+ nextTick(() => {
+ isCommitting = false;
+ });
}
function onKeydown(event: KeyboardEvent) {
diff --git a/apps/desktop/src/components/grid/__tests__/TemporalCellEditorSaveShortcut.spec.ts b/apps/desktop/src/components/grid/__tests__/TemporalCellEditorSaveShortcut.spec.ts
index cb3c16d555..777bcdbd3b 100644
--- a/apps/desktop/src/components/grid/__tests__/TemporalCellEditorSaveShortcut.spec.ts
+++ b/apps/desktop/src/components/grid/__tests__/TemporalCellEditorSaveShortcut.spec.ts
@@ -2,7 +2,7 @@
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
-import { createApp, defineComponent, h, ref, type App } from "vue";
+import { createApp, defineComponent, h, nextTick, ref, type App } from "vue";
import { createPinia, setActivePinia } from "pinia";
import { afterEach, describe, expect, it, vi } from "vitest";
@@ -99,4 +99,42 @@ describe("TemporalCellEditor save shortcut", () => {
expect(cellDetailPanelSource).toContain("@save=\"emit('save')\"");
expect(dataGridSource).toMatch(/onTemporalCellEditorSave\(\)[\s\S]*?saveGridChangesFromShortcut\(\)/);
});
+
+ it("re-arms a persistent instance so a value-editor temporal cell can save repeatedly (#10515)", async () => {
+ // 值编辑器面板用 commitValueEditorEdit 保持 isEditingDetail=true,同一个
+ // TemporalCellEditor 实例一直挂着;每次 ctrl+s 都必须重新提交,不能被首次提交
+ // 后闩锁住的 isCommitting 挡住(修复前第二次提交被短路)。
+ const { input, onCommit, onSave, modelValue } = mountEditor();
+
+ input.value = "2026-03-04 05:06:07";
+ input.dispatchEvent(new Event("input"));
+ keydown(input, { key: "s", ctrlKey: true });
+ await nextTick();
+ expect(onCommit).toHaveBeenCalledTimes(1);
+ expect(onSave).toHaveBeenCalledTimes(1);
+
+ input.value = "2027-07-08 09:10:11";
+ input.dispatchEvent(new Event("input"));
+ keydown(input, { key: "s", ctrlKey: true });
+ await nextTick();
+ expect(onCommit).toHaveBeenCalledTimes(2);
+ expect(onSave).toHaveBeenCalledTimes(2);
+ expect(modelValue.value).toBe("2027-07-08 09:10:11");
+ });
+
+ it("wires onSaveShortcut so the non-temporal value editor can commit + save via Ctrl+S (#10515)", () => {
+ // useCellDetailEditor(CodeMirror)只认 onSaveShortcut;DataGrid 没传时 varchar 等
+ // 非 temporal 值编辑器里 ctrl+s 无人消费(必须点「执行」)。这里做结构校验。
+ expect(dataGridSource).toContain("onSaveShortcut:");
+ expect(dataGridSource).toMatch(/useCellDetailEditor\(\{[\s\S]{0,2000}?onSaveShortcut[\s\S]{0,1200}?commitValueEditorEdit\(\)/);
+ // 回归防护:useCellDetailEditor 对每个 keydown 都会回调 onSaveShortcut,处理器
+ // 必须先用 isSaveShortcut 过滤,否则普通按键也被吞掉,值编辑器完全无法输入。
+ expect(dataGridSource).toMatch(/onSaveShortcut: \(event\) => \{[\s\S]{0,200}?isSaveShortcut\(event, settingsStore\.editorSettings\.shortcuts\)[\s\S]{0,600}?commitValueEditorEdit\(\)/);
+ });
+
+ it("wires Ctrl+S in the cell details panel editor to commit + save (#10515)", () => {
+ // 单元格详情 tab 的 CodeMirror 是另一个编辑器实例;ctrl+s 必须与 temporal 详情
+ // 编辑器的路径一致——先 emit commit(落成待保存变更)再 emit save(触发保存)。
+ expect(cellDetailPanelSource).toMatch(/onSave: \(\) => \{[\s\S]{0,160}?emit\("commit"\);[\s\S]{0,80}?emit\("save"\);/);
+ });
});
diff --git a/apps/desktop/src/composables/__tests__/useDataGridCellDetail.spec.ts b/apps/desktop/src/composables/__tests__/useDataGridCellDetail.spec.ts
index 83f20ab914..f7f1e4b34e 100644
--- a/apps/desktop/src/composables/__tests__/useDataGridCellDetail.spec.ts
+++ b/apps/desktop/src/composables/__tests__/useDataGridCellDetail.spec.ts
@@ -12,12 +12,14 @@ const mocks = vi.hoisted(() => ({
openSearch: vi.fn(),
focus: vi.fn(),
onChange: undefined as undefined | ((value: string) => void),
+ onSaveShortcut: undefined as undefined | ((event: KeyboardEvent) => boolean),
fontFamily: undefined as undefined | (() => string),
}));
vi.mock("@/composables/useCellDetailEditor", () => ({
- useCellDetailEditor: (options: { onChange?: (value: string) => void; fontFamily: () => string }) => {
+ useCellDetailEditor: (options: { onChange?: (value: string) => void; onSaveShortcut?: (event: KeyboardEvent) => boolean; fontFamily: () => string }) => {
mocks.onChange = options.onChange;
+ mocks.onSaveShortcut = options.onSaveShortcut;
mocks.fontFamily = options.fontFamily;
return {
create: mocks.create,
@@ -61,6 +63,7 @@ function detail(): DataGridCellDetail {
beforeEach(() => {
vi.clearAllMocks();
mocks.onChange = undefined;
+ mocks.onSaveShortcut = undefined;
mocks.fontFamily = undefined;
mocks.getValue.mockReturnValue("");
});
@@ -153,4 +156,41 @@ describe("useDataGridCellDetail", () => {
expect(mocks.setValue).not.toHaveBeenCalled();
scope.stop();
});
+
+ it("claims the save shortcut in the details editor and commits + saves via onSave (#10515)", async () => {
+ const scope = effectScope();
+ const onSave = vi.fn();
+ const composable = scope.run(() => useDataGridCellDetail({ detail: ref(detail()), editValue: ref(""), onCancel: vi.fn(), onSave }))!;
+
+ composable.detailsEditorContainer.value = document.createElement("div");
+ await nextTick();
+ expect(mocks.create).toHaveBeenCalledOnce();
+ expect(mocks.onSaveShortcut).toBeTypeOf("function");
+
+ // useCellDetailEditor 会对每个 keydown 回调本钩子;普通按键必须原样放行
+ // (返回 false),否则详情编辑器完全无法输入(#10515 回归)。
+ expect(mocks.onSaveShortcut?.(new KeyboardEvent("keydown", { key: "a" }))).toBe(false);
+ expect(mocks.onSaveShortcut?.(new KeyboardEvent("keydown", { key: "Enter" }))).toBe(false);
+ expect(onSave).not.toHaveBeenCalled();
+
+ expect(mocks.onSaveShortcut?.(new KeyboardEvent("keydown", { key: "s", ctrlKey: true }))).toBe(true);
+ expect(onSave).toHaveBeenCalledOnce();
+
+ composable.detailsEditorContainer.value = undefined;
+ await nextTick();
+ scope.stop();
+ });
+
+ it("does not claim any key when onSave is not provided", async () => {
+ const scope = effectScope();
+ const composable = scope.run(() => useDataGridCellDetail({ detail: ref(detail()), editValue: ref(""), onCancel: vi.fn() }))!;
+
+ composable.detailsEditorContainer.value = document.createElement("div");
+ await nextTick();
+ expect(mocks.onSaveShortcut).toBeUndefined();
+
+ composable.detailsEditorContainer.value = undefined;
+ await nextTick();
+ scope.stop();
+ });
});
diff --git a/apps/desktop/src/composables/useDataGridCellDetail.ts b/apps/desktop/src/composables/useDataGridCellDetail.ts
index 22af4d1bd8..740ee9d4b2 100644
--- a/apps/desktop/src/composables/useDataGridCellDetail.ts
+++ b/apps/desktop/src/composables/useDataGridCellDetail.ts
@@ -1,11 +1,12 @@
import { nextTick, ref, watch, type Ref } from "vue";
import { useCellDetailEditor, type UseCellDetailEditorReturn } from "@/composables/useCellDetailEditor";
+import { isSaveShortcut } from "@/lib/editor/keyboardShortcuts";
import { useTheme } from "@/composables/useTheme";
import { useSettingsStore } from "@/stores/settingsStore";
import { renderWktOnCanvas } from "@/lib/dataGrid/geometryPreview";
import type { DataGridCellDetail } from "@/lib/dataGrid/dataGridDetail";
-export function useDataGridCellDetail(options: { detail: Ref<DataGridCellDetail>; editValue: Ref<string>; onCancel: () => void }) {
+export function useDataGridCellDetail(options: { detail: Ref<DataGridCellDetail>; editValue: Ref<string>; onCancel: () => void; onSave?: () => void }) {
const settingsStore = useSettingsStore();
const { isDark, themePalette } = useTheme();
const geometryPreviewOpen = ref(false);
@@ -33,7 +34,21 @@ export function useDataGridCellDetail(options: { detail: Ref<DataGridCellDetail>
watch(detailsEditorContainer, async (element) => {
if (element && !detailsEditor) {
- const editor = useCellDetailEditor({ onChange: (value) => (options.editValue.value = value), onEscape: options.onCancel, ...editorOptions() });
+ const editor = useCellDetailEditor({
+ onChange: (value) => (options.editValue.value = value),
+ onEscape: options.onCancel,
+ // 详情面板 CodeMirror 里的 Ctrl/Cmd+S:提交草稿成待保存变更并保存(#10515)。
+ // useCellDetailEditor 对每个 keydown 都会回调本钩子,必须先用 isSaveShortcut
+ // 过滤,否则普通按键也会被吞掉(preventDefault)导致无法输入。
+ onSaveShortcut: options.onSave
+ ? (event) => {
+ if (!isSaveShortcut(event, settingsStore.editorSettings.shortcuts)) return false;
+ options.onSave?.();
+ return true;
+ }
+ : undefined,
+ ...editorOptions(),
+ });
detailsEditor = editor;
await editor.create(element, options.editValue.value, options.detail.value.type);
if (detailsEditor === editor && editor.getValue() !== options.editValue.value) {