fix(editor): commit a keyed series before a move or a redraw starts
Safari, and iPad Safari on a tap, focuses no clicked button: the
handle or the slider keeps the focus, no blur commits its series, and
« Déplacer … », « Redessiner » or « Remplacer par un polygone »
cleared it (preview: null) without a word. startMove and beginRedraw
now call commitFocusedSeries() first, the same path a drawing press
takes since 10a8767. « Propriétés » (guardDrawing) and
« Désélectionner » (useDeselect) already committed; a test pins both.
Tests: no assertion removed.
This commit is contained in:
1 parent
a5af9bdd4f
commit
a75c2999de
4 files changed
+86
No files matched your search
@@ -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<UiAction>): 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 })
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
},
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
})
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user