From 10a87675274d02b6abb76ae190f06a35519f7e21 Mon Sep 17 00:00:00 2001 From: bchanot Date: Wed, 18 Nov 2026 13:12:55 +0100 Subject: [PATCH] fix(editor): commit a keyed series as a press starts on the drawing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Final review I-1 audit. A touch press moves no focus before its pointer-up, so a press on « + » or « − », or a drag, committed over an arrow or slider series still pending on the focused handle and dropped it. A fresh press now commits it first (commitFocusedSeries, its own blur), as the mouse's focus move already did. Tests: no assertion removed; header « Refaire » cases added for a started redraw and a size change. --- .../src/editor/annotations/usePressGesture.ts | 5 ++ .../tests/unit/editor-undo-shortcuts.test.tsx | 10 ++++ apps/app/tests/unit/editor-zone-edit.test.tsx | 52 +++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/apps/app/src/editor/annotations/usePressGesture.ts b/apps/app/src/editor/annotations/usePressGesture.ts index 99267816..7b5667cf 100644 --- a/apps/app/src/editor/annotations/usePressGesture.ts +++ b/apps/app/src/editor/annotations/usePressGesture.ts @@ -25,6 +25,7 @@ import { import type { ToolId } from './uiState' import { annotationIdOf } from './useCanvasBuild' import { useBlockDrag, type BlockDragInput } from './useBlockDrag' +import { commitFocusedSeries } from './drawingGuard' import { useAnnotationWork } from './workStore' export interface PressInput extends BlockDragInput { @@ -291,6 +292,10 @@ function startPress(latest: RefObject, event: PointerEvent): void { const f = latest.current const m = f.machine.current if (m.press.phase !== 'idle') feed(f, { type: 'cancel' }, null) + // Final review I-1: a series keyed on a handle or the slider commits as a new press + // starts, as the mouse's focus move does; a touch moves no focus before its pointer-up, + // so a « + », a « − » or a drag would otherwise commit over it and drop it. + commitFocusedSeries() m.pressedAt = clientOf(event) const kind = pointerKindOf(event.pointerType) const context = { kind, ...contextOf(f.input) } diff --git a/apps/app/tests/unit/editor-undo-shortcuts.test.tsx b/apps/app/tests/unit/editor-undo-shortcuts.test.tsx index 49b9c065..67d7d386 100644 --- a/apps/app/tests/unit/editor-undo-shortcuts.test.tsx +++ b/apps/app/tests/unit/editor-undo-shortcuts.test.tsx @@ -175,6 +175,16 @@ describe('redo with something pending (final review I-1)', () => { expect(redo).toHaveAttribute('aria-disabled', 'true') }) + it('the header « Refaire » is off and keeps a pending size change', async () => { + await undone() + pend('size') + const redo = screen.getByRole('button', { name: REDO }) + fireEvent.click(redo) + expect(useAnnotationWork.getState().preview?.source).toBe('size') + expect(cx()).toMatchObject({ cx: 50 }) + expect(redo).toHaveAttribute('aria-disabled', 'true') + }) + it('once the work is gone, redo works again', async () => { await undone() pend('keys') diff --git a/apps/app/tests/unit/editor-zone-edit.test.tsx b/apps/app/tests/unit/editor-zone-edit.test.tsx index 9f1ee76c..0b48d6db 100644 --- a/apps/app/tests/unit/editor-zone-edit.test.tsx +++ b/apps/app/tests/unit/editor-zone-edit.test.tsx @@ -975,6 +975,25 @@ describe('final review I-1: a redo or a handle key never drops pending work', () expect(screen.queryByText(ABANDONED)).toBeNull() }) + it('the header « Refaire » is off in a started redraw and keeps it', async () => { + await withRedo() + render() + await userEvent + .setup() + .click(screen.getByRole('button', { name: 'Redessiner' })) + pressAt(canvas(), 30, 30) + const redo = screen.getByRole('button', { + name: 'Refaire la dernière modification défaite', + }) + fireEvent.click(redo) + expect(useAnnotationWork.getState().mode).toMatchObject({ + kind: 'redraw', + started: true, + }) + expect(store.getState().redo).toHaveLength(1) + expect(redo).toHaveAttribute('aria-disabled', 'true') + }) + it('in a started zone move, Enter or Space on « + » and Insert change nothing', async () => { await mount(squareText()) await select() @@ -1006,6 +1025,39 @@ describe('final review I-1: a redo or a handle key never drops pending work', () }) }) +describe('final review I-1 audit: a press on the drawing never drops a keyed series', () => { + // A touch press moves the focus only after its pointer-up (if at all), and happy-dom + // moves none: the keyed vertex keeps the focus and no blur commits its series. + async function keyed(points: Point[] = SQUARE) { + await mount(squareText(points)) + await select() + act(() => vertex(1).focus()) + fireEvent.keyDown(vertex(1), { key: 'ArrowRight' }) + expect(useAnnotationWork.getState().preview?.source).toBe('keys') + return depth() + } + + it('a press on « + »: the step is committed, then the insert', async () => { + const before = await keyed() + clickHandle('Ajouter un sommet après le sommet 1', [50.25, 20]) + expect(pointsOf('z')).toEqual([[20.5, 20], [50.25, 20], ...SQUARE.slice(1)]) + expect(depth()).toBe(before + 2) + }) + + it('a press on « − »: the step is committed, then the removal', async () => { + const before = await keyed([...SQUARE, [10, 50]]) + clickHandle('Retirer le sommet 1', [20.5, 20]) + expect(pointsOf('z')).toEqual([...SQUARE.slice(1), [10, 50]]) + expect(depth()).toBe(before + 2) + }) + + it('a drag of another vertex carries the keyed step', async () => { + await keyed() + drag(hitOf('Sommet 2'), [80, 20], [90, 10]) + expect(pointsOf('z')).toEqual([[20.5, 20], [90, 10], ...SQUARE.slice(2)]) + }) +}) + describe('final review M-6: a redraw gives the focus back to « Redessiner »', () => { const canvas = () => screen.getByTestId('annotation-canvas') const TRACE: [number, number][] = [