fix(grid): save value editor and cell detail edits via Ctrl+S
This commit is contained in:
1 parent
26ab78f2d3
commit
b41538ba6b
6 files changed
+130
-5
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+39
-1
@@ -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"\);/);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user