diff --git a/apps/app/e2e/shell/editor-annotations.spec.ts b/apps/app/e2e/shell/editor-annotations.spec.ts index c71b9895..058267c8 100644 --- a/apps/app/e2e/shell/editor-annotations.spec.ts +++ b/apps/app/e2e/shell/editor-annotations.spec.ts @@ -247,6 +247,39 @@ test.describe('editor annotations (A3)', () => { await expect(page.getByTestId('gesture-message')).toHaveCount(1) }) + test('a mouse click on « Refaire » during an arrow series says why and keeps the focus', async ({ + page, + requests, + }) => { + const { actor } = await openAnnotations(page) + requests.forbid(actor.account.email, actor.account.password) + await tool(page, 'point').click() + await clickDrawing(page, 300, 300) + await fillCreation(page, { fr: 'Point un', en: 'Point one' }) + await createFromPanel(page) + const handle = page.getByRole('button', { + name: 'Point Point un', + exact: true, + }) + await handle.focus() + await page.keyboard.press('ArrowRight') + const redo = historyButton(page, dict, 'redo') + await expect(redo).toHaveAccessibleDescription( + dict['editor.history.hold_pending'], + ) + // Playwright refuses to click an aria-disabled button: scroll it clear of the sticky + // bar, then press it by force (the mouse events are real). + await redo.evaluate((el) => el.scrollIntoView({ block: 'center' })) + await redo.click({ force: true }) + await expect(page.getByTestId('gesture-line')).toContainText( + dict['editor.history.hold_pending'], + ) + await expect(handle).toBeFocused() + await expect(redo).toHaveAccessibleDescription( + dict['editor.history.hold_pending'], + ) + }) + test('a click with jitter never moves; a drag moves by the pointer delta', async ({ page, requests, diff --git a/apps/app/src/components/editor/HistoryButtons.tsx b/apps/app/src/components/editor/HistoryButtons.tsx index 0eee07f0..0ed2e400 100644 --- a/apps/app/src/components/editor/HistoryButtons.tsx +++ b/apps/app/src/components/editor/HistoryButtons.tsx @@ -1,6 +1,7 @@ import { useRef, type FocusEvent, + type MouseEvent, type PointerEvent, type RefObject, } from 'react' @@ -77,7 +78,13 @@ function usePress( const onPointerLeave = (event: PointerEvent) => { if (event.pointerType === 'mouse') forget() } + const isHeld = () => holdOf(direction, useAnnotationWork.getState()) !== null + // A held press only says why: the focus stays on the pending work, which is not committed. + const onMouseDown = (event: MouseEvent) => { + if (isHeld()) event.preventDefault() + } const onPointerDown = () => { + if (isHeld()) return left.current = asField(document.activeElement) ?? left.current commitFocusedField() } @@ -104,6 +111,7 @@ function usePress( } return { onPointerDown, + onMouseDown, onFocus, onBlur, onPointerLeave, diff --git a/apps/app/tests/unit/editor-history-buttons.test.tsx b/apps/app/tests/unit/editor-history-buttons.test.tsx index 9ba4c280..5b3af9e5 100644 --- a/apps/app/tests/unit/editor-history-buttons.test.tsx +++ b/apps/app/tests/unit/editor-history-buttons.test.tsx @@ -638,6 +638,41 @@ describe('why a button is held (point 6)', () => { expect(line()).toHaveTextContent(PENDING) }) + it('a mouse press on a held « Refaire » leaves the focused pending work alone', async () => { + const user = await openAnnotations() + pend() + // A handle's blur commits its series (here: ends the preview), as the real one does. + const handle = document.createElement('button') + handle.addEventListener('blur', () => + useAnnotationWork.setState({ preview: null }), + ) + document.body.append(handle) + handle.focus() + store.setState({ redo: [{ text: baseText(), bytes: 1 }] }) + await user.pointer([ + { keys: '[MouseLeft>]', target: redoButton() }, + { keys: '[/MouseLeft]' }, + ]) + expect(handle).toHaveFocus() + expect(useAnnotationWork.getState().preview).not.toBeNull() + expect(store.getState().redo).toHaveLength(1) + expect(line()).toHaveTextContent(PENDING) + handle.remove() + }) + + it('Space on a held « Défaire » and Enter on a pending « Refaire » say why', async () => { + const user = await openAnnotations() + create() + undoButton().focus() + await user.keyboard(' ') + expect(line()).toHaveTextContent(CREATION) + act(() => resetWork()) + pend() + redoButton().focus() + await user.keyboard('{Enter}') + expect(line()).toHaveTextContent(PENDING) + }) + it('say it in English', async () => { const user = await openAnnotations() act(() => useLocaleStore.setState({ locale: 'en' }))