fix(editor): a press on a held redo keeps the pending work untouched

This commit is contained in:
bchanot committed 2026-11-19 14:02:11 +01:00
1 parent 00e995a6cb
commit 8f036b2a8a
3 files changed
+76

No files matched your search

@@ -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,
@@ -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<HTMLElement>) => {
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<HTMLElement>) => {
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,
@@ -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' }))