fix(editor): commit a keyed series as a press starts on the drawing
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.
This commit is contained in:
1 parent
13e2503e6a
commit
10a8767527
3 files changed
+67
No files matched your search
@@ -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<Feed>, 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) }
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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(<HistoryButtons />)
|
||||
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][] = [
|
||||
|
||||
Reference in new issue
Block a user