From a036ea1e8d337dffd9c1e7e0869bedbf21c1f0f6 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Thu, 28 May 2026 18:31:57 +0800 Subject: [PATCH] fix(grid): sync value editor with selected cell --- apps/desktop/src/components/grid/DataGrid.vue | 12 ++++++++++-- packages/app-tests/cellDetailPresentation.test.ts | 14 +++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue index c430fac03..4f4bc9cf0 100644 --- a/apps/desktop/src/components/grid/DataGrid.vue +++ b/apps/desktop/src/components/grid/DataGrid.vue @@ -2195,8 +2195,16 @@ async function prefetchDetailSqlCondition() { } } -watch(activeCellDetail, () => { +watch(activeCellDetail, (detail) => { void prefetchDetailSqlCondition(); + if (activeCellDetailTab.value !== "valueEditor") return; + if (!detail?.isEditable) { + resetDetailEdit(); + return; + } + detailEditValue.value = cellDetailEditorText(detail.value, detail.type); + syncEditorFromDetailEdit(); + isEditingDetail.value = true; }); const detailEditValue = ref(""); @@ -2658,7 +2666,7 @@ watch([selectedRange, showCellDetail, isEditingDetail], () => { const selectedCell = currentSelectedCellPosition(); const target = linkedCellDetailTarget({ isOpen: showCellDetail.value, - isEditing: isEditingDetail.value, + isEditing: isEditingDetail.value && activeCellDetailTab.value !== "valueEditor", selectedCell: selectedCell ? { rowIndex: selectedCell.rowIndex, visibleColIndex: selectedCell.colIndex } : null, actualColumnIndex, }); diff --git a/packages/app-tests/cellDetailPresentation.test.ts b/packages/app-tests/cellDetailPresentation.test.ts index 2d04d11b2..7e1b97061 100644 --- a/packages/app-tests/cellDetailPresentation.test.ts +++ b/packages/app-tests/cellDetailPresentation.test.ts @@ -86,6 +86,18 @@ test("cell detail action focuses the hovered cell before opening details", () => /function showCellDetailsForVisibleCell\(rowIndex: number, visibleColIdx: number, actualColIdx: number\)/, ); assert.match(source, /selectSingleCell\(rowIndex, visibleColIdx\)/); - assert.match(source, /@click\.stop="showCellDetailsForVisibleCell\(item\.displayIndex, visibleColIdx, actualColIdx\)"/); + assert.match( + source, + /@click\.stop="showCellDetailsForVisibleCell\(item\.displayIndex, visibleColIdx, actualColIdx\)"/, + ); assert.doesNotMatch(source, /@click\.stop="showCellDetails\(item\.displayIndex, actualColIdx\)"/); }); + +test("cell detail value editor follows selection and refreshes the editor content", () => { + const source = readFileSync("apps/desktop/src/components/grid/DataGrid.vue", "utf8"); + + assert.match(source, /if \(activeCellDetailTab\.value !== "valueEditor"\) return;/); + assert.match(source, /detailEditValue\.value = cellDetailEditorText\(detail\.value, detail\.type\)/); + assert.match(source, /syncEditorFromDetailEdit\(\)/); + assert.match(source, /isEditing: isEditingDetail\.value && activeCellDetailTab\.value !== "valueEditor"/); +});