diff --git a/apps/app/src/editor/annotations/redraw.ts b/apps/app/src/editor/annotations/redraw.ts index 62a3f74a..1754701d 100644 --- a/apps/app/src/editor/annotations/redraw.ts +++ b/apps/app/src/editor/annotations/redraw.ts @@ -1,5 +1,6 @@ import { useEffect, useRef, type Dispatch } from 'react' import { useEditorStore } from '../state/editorStore' +import { commitFocusedSeries } from './drawingGuard' import type { Tracing, UiAction } from './uiState' import { endMode, @@ -13,6 +14,8 @@ import { * guard reads (R-12), and the tracing target `replace` that draws the new polygon. */ export function beginRedraw(id: string, dispatch: Dispatch): void { + // A series still pending (Safari focuses no clicked button) commits first. + commitFocusedSeries() startRedraw(id, useEditorStore.getState().documentText) dispatch({ type: 'trace_start', target: 'replace', annotationId: id }) } diff --git a/apps/app/src/editor/annotations/usePointEdit.ts b/apps/app/src/editor/annotations/usePointEdit.ts index d0335ed4..716f1fc7 100644 --- a/apps/app/src/editor/annotations/usePointEdit.ts +++ b/apps/app/src/editor/annotations/usePointEdit.ts @@ -1,6 +1,7 @@ import type { KeyboardEvent } from 'react' import type { Annotation } from '@faunosteo/core-wasm/types' import { useEditorStore } from '../state/editorStore' +import { commitFocusedSeries } from './drawingGuard' import { moveStep, type Frame } from './frame' import type { Drop } from './usePlacement' import { takeMove, takePreview, stepSelection } from './previewCommit' @@ -110,6 +111,8 @@ export function usePointEdit(input: PointEditInput) { startMove: () => { const id = input.target?.id if (!id) return + // A series still pending (Safari focuses no clicked button) commits first. + commitFocusedSeries() const base = useEditorStore.getState().documentText startMove(id, base, freshChosen(id)) }, diff --git a/apps/app/tests/unit/editor-point-edit.test.tsx b/apps/app/tests/unit/editor-point-edit.test.tsx index 4c3de457..4dcff028 100644 --- a/apps/app/tests/unit/editor-point-edit.test.tsx +++ b/apps/app/tests/unit/editor-point-edit.test.tsx @@ -719,3 +719,32 @@ describe('fix round 1: no silent loss on the way out', () => { expect(screen.getByTestId('move-mode-bar')).toBeInTheDocument() }) }) + +describe('Safari: « Déplacer le point » clicked with the focus left on the slider', () => { + it('commits the size change, then starts the mode', async () => { + await mount(withPoints(point('a', 50, 50, 5), point('b', 20, 20, 8))) + await select() + act(() => slider().focus()) + fireEvent.keyDown(slider(), { key: 'PageUp' }) + const before = depth() + fireEvent.click(moveButton()) + expect(geometryOf('a')).toMatchObject({ r: 8 }) + expect(depth()).toBe(before + 1) + expect(useAnnotationWork.getState().mode).toMatchObject({ + kind: 'move', + base: store.getState().documentText, + }) + }) + + it('commits an arrow series on the point handle the same way', async () => { + await mount(withPoints(point('a', 50, 50, 5))) + await select() + act(() => handle().focus()) + fireEvent.keyDown(handle(), { key: 'ArrowRight' }) + const before = depth() + fireEvent.click(moveButton()) + expect(geometryOf('a')).not.toMatchObject({ cx: 50 }) + expect(depth()).toBe(before + 1) + expect(useAnnotationWork.getState().mode?.kind).toBe('move') + }) +}) diff --git a/apps/app/tests/unit/editor-zone-edit.test.tsx b/apps/app/tests/unit/editor-zone-edit.test.tsx index 0b48d6db..d3bb3505 100644 --- a/apps/app/tests/unit/editor-zone-edit.test.tsx +++ b/apps/app/tests/unit/editor-zone-edit.test.tsx @@ -1137,3 +1137,54 @@ describe('final review M-6: a redraw gives the focus back to « Redessiner »', expect(document.activeElement).toBe(redrawButton()) }) }) + +describe('Safari: a strip command clicked with the focus left on a keyed vertex', () => { + // Safari (and iPad Safari on a tap) does not focus a clicked button: no blur commits the + // series, so the command itself must (coordinator ruling on the final fix report). + async function keyedVertex() { + await mount(squareText()) + await select() + clickHandle('Sommet 1', [20, 20]) + act(() => vertex(1).focus()) + fireEvent.keyDown(vertex(1), { key: 'ArrowRight' }) + expect(useAnnotationWork.getState().preview?.source).toBe('keys') + return depth() + } + + it('« Déplacer le sommet » commits the step, then starts the mode', async () => { + const before = await keyedVertex() + fireEvent.click(screen.getByRole('button', { name: 'Déplacer le sommet' })) + expect(pointsOf('z')![0]).toEqual([20.5, 20]) + expect(depth()).toBe(before + 1) + expect(useAnnotationWork.getState().mode).toMatchObject({ + kind: 'move', + started: false, + base: store.getState().documentText, + }) + }) + + it('« Redessiner » commits the step, then starts the redraw', async () => { + const before = await keyedVertex() + fireEvent.click(screen.getByRole('button', { name: 'Redessiner' })) + expect(pointsOf('z')![0]).toEqual([20.5, 20]) + expect(depth()).toBe(before + 1) + expect(useAnnotationWork.getState().mode).toMatchObject({ + kind: 'redraw', + base: store.getState().documentText, + }) + }) + + it('« Propriétés » and « Désélectionner » already commit it', async () => { + let before = await keyedVertex() + fireEvent.click(screen.getByRole('button', { name: 'Propriétés' })) + expect(pointsOf('z')![0]).toEqual([20.5, 20]) + expect(depth()).toBe(before + 1) + cleanup() + resetStore() + resetWork() + before = await keyedVertex() + fireEvent.click(screen.getByRole('button', { name: 'Désélectionner' })) + expect(pointsOf('z')![0]).toEqual([20.5, 20]) + expect(depth()).toBe(before + 1) + }) +})