fix(editor): redo and move-mode handle keys keep pending work

Final review I-1. Redo (Ctrl+Shift+Z and the header « Refaire ») is
inactive while a started move or redraw, a keyboard series or a size
change is pending (holdsRedo): the work stays, the user commits or
cancels it first. In a move mode, Insert and Delete on a vertex and
Enter or Space on « + » and « − » do nothing, as the press machine.

Tests: no assertion removed. The history-guards move-mode helper and
reset run in act, since « Refaire » now re-renders on a started mode.
This commit is contained in:
bchanot committed 2026-11-18 13:00:03 +01:00
1 parent c6b8c7e48a
commit ae80511964
7 files changed
+211 -12

No files matched your search

@@ -131,3 +131,57 @@ describe('undo with something pending (R-13)', () => {
expect(cx()).toMatchObject({ cx: 50 })
})
})
describe('redo with something pending (final review I-1)', () => {
const REDO = 'Refaire la dernière modification défaite'
/** A commit undone: the redo stack holds it, the shape is back at cx 50. */
async function undone() {
mountDraft()
await ready()
act(() => void commitMove(40))
ctrlZ(document.body)
expect(cx()).toMatchObject({ cx: 50 })
}
const pend = (source: 'keys' | 'size') => {
const stored = store.getState().previewState!.document.annotations[0]
act(() =>
useAnnotationWork.setState({
preview: {
annotationId: stored.id,
geometry: { type: 'circle', cx: 60, cy: 50, r: 10 },
base: store.getState().documentText,
source,
},
}),
)
}
it('Ctrl+Shift+Z keeps a pending size change and redoes nothing', async () => {
await undone()
pend('size')
ctrlZ(document.body, true)
expect(useAnnotationWork.getState().preview?.source).toBe('size')
expect(cx()).toMatchObject({ cx: 50 })
})
it('the header « Refaire » is off and keeps a keyboard series', async () => {
await undone()
pend('keys')
const redo = screen.getByRole('button', { name: REDO })
// A click that leaves the focus in place (Safari does not focus a clicked button).
fireEvent.click(redo)
expect(useAnnotationWork.getState().preview?.source).toBe('keys')
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')
act(() => useAnnotationWork.setState({ preview: null }))
const redo = screen.getByRole('button', { name: REDO })
expect(redo).toHaveAttribute('aria-disabled', 'false')
fireEvent.click(redo)
expect(cx()).toMatchObject({ cx: 40 })
})
})