fix(grid): restore first double-click cell editing

This commit is contained in:
zipg
2026-08-26 10:04:44 +08:00
committed by GitHub
parent 8bcbfd7ae7
commit dc10323b7c
2 changed files with 27 additions and 8 deletions
+11 -8
View File
@@ -7088,8 +7088,13 @@ function canvasColumnAt(contentX: number): number {
return low;
}
function canvasEventSurface(event: MouseEvent): HTMLCanvasElement | null {
const currentTarget = event.currentTarget;
return currentTarget instanceof HTMLCanvasElement ? currentTarget : activeCanvasSurface();
}
function canvasHitTest(event: MouseEvent): { rowIndex: number; visibleColIdx: number; rowNumber: boolean } | null {
const canvas = activeCanvasSurface();
const canvas = canvasEventSurface(event);
const scroller = canvasScrollerElement();
if (!canvas || !scroller) return null;
const rect = canvas.getBoundingClientRect();
@@ -7203,8 +7208,8 @@ function onDomGridWheel(event: WheelEvent) {
function onCanvasMouseMove(event: MouseEvent) {
stopReleasedSelectionGesture(event);
const cursorSurface = canvasEventSurface(event);
if (columnHeaderPointerInteractionActive()) {
const cursorSurface = activeCanvasSurface();
if (cursorSurface) cursorSurface.style.cursor = "default";
onCanvasMouseLeave();
return;
@@ -7219,7 +7224,6 @@ function onCanvasMouseMove(event: MouseEvent) {
}
: null;
const actualColIdx = next ? visibleColumnIndexes.value[next.visibleColIdx] : undefined;
const cursorSurface = activeCanvasSurface();
if (cursorSurface) {
const overBooleanInteractive =
booleanCellsUseCheckbox.value && hit != null && !hit.rowNumber && hitItem != null && actualColIdx !== undefined && isBooleanGridCell(hitItem, actualColIdx) && canEditCellItem(hitItem, actualColIdx) && booleanInteractiveHitFromCanvasEvent(hitItem, hit, actualColIdx, event);
@@ -7271,7 +7275,7 @@ function clearCanvasDetailHover(event?: MouseEvent) {
function booleanCheckboxHitFromCanvasEvent(item: RowItem, hit: { rowIndex: number; visibleColIdx: number }, actualColIdx: number, event: MouseEvent): boolean {
if (item.data[actualColIdx] === null) return false;
const canvas = activeCanvasSurface();
const canvas = canvasEventSurface(event);
const canvasRect = canvas?.getBoundingClientRect();
const cellRect = canvasCellViewportRect(hit.rowIndex, hit.visibleColIdx);
if (!canvasRect || !cellRect) return false;
@@ -7288,7 +7292,7 @@ function booleanCheckboxHitFromCanvasEvent(item: RowItem, hit: { rowIndex: numbe
function booleanNullTextHitFromCanvasEvent(item: RowItem, hit: { rowIndex: number; visibleColIdx: number }, actualColIdx: number, event: MouseEvent): boolean {
if (item.data[actualColIdx] !== null) return false;
const canvas = activeCanvasSurface();
const canvas = canvasEventSurface(event);
const canvasRect = canvas?.getBoundingClientRect();
const cellRect = canvasCellViewportRect(hit.rowIndex, hit.visibleColIdx);
if (!canvasRect || !cellRect) return false;
@@ -12949,6 +12953,7 @@ function currentGridContextMenuItems(): ContextMenuItem[] {
width: `${totalWidth}px`,
height: `${canvasContentHeight}px`,
}"
@dblclick="onCanvasDblClick"
>
<canvas
ref="canvasRef"
@@ -12962,7 +12967,6 @@ function currentGridContextMenuItems(): ContextMenuItem[] {
@mouseleave="onCanvasMouseLeave"
@mousedown="onCanvasMouseDown"
@contextmenu="onCanvasContext"
@dblclick="onCanvasDblClick"
/>
<canvas
ref="canvasBackRef"
@@ -12976,9 +12980,8 @@ function currentGridContextMenuItems(): ContextMenuItem[] {
@mouseleave="onCanvasMouseLeave"
@mousedown="onCanvasMouseDown"
@contextmenu="onCanvasContext"
@dblclick="onCanvasDblClick"
/>
<div ref="canvasOverlayRef" class="canvas-grid-overlay dbx-data-grid-font-family sticky left-0 top-0 z-10 overflow-visible" :style="canvasOverlayStyle">
<div ref="canvasOverlayRef" class="canvas-grid-overlay dbx-data-grid-font-family sticky left-0 top-0 z-10 overflow-visible" :style="canvasOverlayStyle" @dblclick.stop>
<div v-if="canvasReadonlyTextCell" class="absolute pointer-events-auto z-20 tabular-nums" :style="canvasReadonlyTextCellStyle" @mousedown.stop @click.stop>
<DataGridReadonlyTextSelection :value="canvasReadonlyTextCell.value" :expanded="canvasReadonlyTextCell.expanded" @close="closeReadonlyCellTextSelection" @escape="escapeReadonlyCellTextSelection" />
</div>
@@ -142,6 +142,22 @@ describe("DataGrid canvas surfaces", () => {
expect(dataGridSource).toContain("const canvas = inactiveCanvasSurface();");
expect(dataGridSource).toContain("canvasUsingBackSurface.value = !canvasUsingBackSurface.value;");
});
it("uses the canvas that actually received the event during a surface flip", () => {
expect(dataGridSource).toContain("function canvasEventSurface(event: MouseEvent): HTMLCanvasElement | null");
expect(dataGridSource).toContain("const currentTarget = event.currentTarget;");
expect(dataGridSource).toContain("return currentTarget instanceof HTMLCanvasElement ? currentTarget : activeCanvasSurface();");
expect(dataGridSource).toContain("const canvas = canvasEventSurface(event);");
const canvasMouseMove = dataGridSource.slice(dataGridSource.indexOf("function onCanvasMouseMove"), dataGridSource.indexOf("function onCanvasMouseLeave"));
expect(canvasMouseMove).toContain("const cursorSurface = canvasEventSurface(event);");
});
it("handles double clicks on the stable canvas container", () => {
expect(dataGridSource).toContain('@dblclick="onCanvasDblClick"');
expect(dataGridSource.match(/@dblclick="onCanvasDblClick"/g)).toHaveLength(1);
expect(dataGridSource).toContain("@dblclick.stop");
});
});
describe("DataGridSearchBar", () => {