refactor(editor): one press machine for clicks, drags and taps on the drawing

press.ts (pure: slop per pointer kind, nearest handle, press target, click
and drag actions, double click, stepPress) is now the editor canvas's only
decider; useCanvasGestures no longer uses clickHandler, useEmptyTap,
swallowClick nor useMoveGesture (deleted), and the box has no onClick.
canPan = dragAction(press target).type === 'pan' at pointer-down; framing
keys only when the box itself is the target. workStore.ts holds the U2
work with stale stamps: dropStale on every documentText change, reset on
a new session (editorStore subscription). The catalogue keeps useFraming
defaults and useEmptyTap, unchanged.

Named change (A13): a finger drag on a selected zone's (or circle link's)
interior moves nothing; the selected point is its own handle and still
moves by any pointer. Second observable change: touch and pen taps are
decided at the pointer-up from the press target, no longer from the
following click (no browser touch adjustment toward a marker).

tests/setup.ts: happy-dom has no elementsFromPoint; a shim answers the
pointerdown target and its ancestors.

Rewritten tests (editor-annotations-tab.test.tsx, D6b):
- "a touch tap deselects in its own click, not at the pointer-up" ->
  "a touch tap deselects at the pointer-up" (deselected after pointerup)
- "a touch tap whose click lands on a marker (adjustment) selects that
  marker" -> "a touch tap is decided by its press: a click adjusted toward
  a marker selects nothing" (deselected, announced, marker b not current)
- "a pen tap deselects in its own click, like a touch tap" -> "a pen tap
  deselects at the pointer-up, like a mouse tap"
- "a pen tap whose click lands on a marker selects that marker" -> "a pen
  tap is decided by its press: a click landing on a marker selects
  nothing"
Added: "a finger drags the selected point (its handle), never a selected
zone (A13)".
Drive-only changes, assertions unchanged: canvas fireEvent.click(x, y)
-> pressAt (pointerdown + pointerup) in the tab suite (C26, tracing,
paths, H3, H6, H8, filter reselect), editor-keep-alive and
editor-sections; drag moves carry buttons: 1 (C34, polygon block move,
H8 lostpointercapture and read-only, editor-no-loss drag in flight),
since a move without a button is a hover.
This commit is contained in:
bchanot committed 2026-11-17 16:56:35 +01:00
1 parent 5ca2b7e3ad
commit 08d266c89f
18 files changed
+1341 -311

No files matched your search

@@ -27,6 +27,7 @@ import {
commitMove,
openReady,
resetStore,
pressAt,
sb,
store,
versionAnswer,
@@ -274,10 +275,7 @@ describe('the point tool and the corrected position (C26)', () => {
async function clickCorner() {
const user = userEvent.setup()
await user.click(screen.getByRole('button', { name: 'Point' }))
fireEvent.click(screen.getByTestId('annotation-canvas'), {
clientX: 0,
clientY: 0,
})
pressAt(screen.getByTestId('annotation-canvas'), 0, 0)
return user
}
@@ -351,10 +349,7 @@ describe('the point tool and the corrected position (C26)', () => {
)
const user = userEvent.setup()
await user.click(screen.getByRole('button', { name: 'Point' }))
fireEvent.click(screen.getByTestId('annotation-canvas'), {
clientX: -5,
clientY: 50,
})
pressAt(screen.getByTestId('annotation-canvas'), -5, 50)
expect(
await screen.findByText("Cliquez à l'intérieur du dessin."),
).toBeInTheDocument()
@@ -379,7 +374,12 @@ describe('select and move gestures (C34)', () => {
pointerId: 1,
})
const moveTo = (el: Element, x: number, y: number) =>
fireEvent.pointerMove(el, { clientX: x, clientY: y, pointerId: 1 })
fireEvent.pointerMove(el, {
clientX: x,
clientY: y,
pointerId: 1,
buttons: 1,
})
const up = (el: Element, x: number, y: number) =>
fireEvent.pointerUp(el, { clientX: x, clientY: y, pointerId: 1 })
@@ -555,10 +555,7 @@ const zoneAnnotation = (geometry: object): Annotation =>
describe('tracing a zone or a link', () => {
const clickAt = (x: number, y: number) =>
fireEvent.click(screen.getByTestId('annotation-canvas'), {
clientX: x,
clientY: y,
})
pressAt(screen.getByTestId('annotation-canvas'), x, y)
it('closes on Enter, holds the polygon pending, inserts it on « Créer »', async () => {
await mount({ text: drawnText() })
@@ -689,7 +686,12 @@ describe('polygons and paths', () => {
button: 0,
pointerId: 1,
})
fireEvent.pointerMove(hit, { clientX: 55, clientY: 40, pointerId: 1 })
fireEvent.pointerMove(hit, {
clientX: 55,
clientY: 40,
pointerId: 1,
buttons: 1,
})
fireEvent.pointerUp(hit, { clientX: 60, clientY: 45, pointerId: 1 })
expect(geometryOf('zone-a')).toMatchObject({
points: [
@@ -712,9 +714,7 @@ describe('polygons and paths', () => {
}),
)
const canvas = screen.getByTestId('annotation-canvas')
triangle.forEach(([x, y]) =>
fireEvent.click(canvas, { clientX: x, clientY: y }),
)
triangle.forEach(([x, y]) => pressAt(canvas, x, y))
fireEvent.keyDown(canvas, { key: 'Enter' })
await waitFor(() =>
expect(geometryOf('zone-a')).toEqual({
@@ -727,10 +727,7 @@ describe('polygons and paths', () => {
describe('keys while tracing (H3)', () => {
const clickAt = (x: number, y: number) =>
fireEvent.click(screen.getByTestId('annotation-canvas'), {
clientX: x,
clientY: y,
})
pressAt(screen.getByTestId('annotation-canvas'), x, y)
async function traced() {
await mount({ text: drawnText() })
@@ -774,15 +771,9 @@ describe('a second click with the point tool (H6)', () => {
)
const user = userEvent.setup()
await user.click(screen.getByRole('button', { name: 'Point' }))
fireEvent.click(screen.getByTestId('annotation-canvas'), {
clientX: 50,
clientY: 50,
})
pressAt(screen.getByTestId('annotation-canvas'), 50, 50)
const panel = await fillCreation(user)
fireEvent.click(screen.getByTestId('annotation-canvas'), {
clientX: 60,
clientY: 40,
})
pressAt(screen.getByTestId('annotation-canvas'), 60, 40)
await waitFor(() =>
expect(within(panel).getByLabelText('Centre x')).toHaveValue('60'),
)
@@ -867,7 +858,7 @@ describe('refusals through the tab (H8)', () => {
[20, 20],
[500, 20],
[50, 80],
].forEach(([x, y]) => fireEvent.click(canvas, { clientX: x, clientY: y }))
].forEach(([x, y]) => pressAt(canvas, x, y))
fireEvent.keyDown(canvas, { key: 'Enter' })
expect(await screen.findByRole('alert')).toBeInTheDocument()
expect(
@@ -917,7 +908,12 @@ describe('the drag and the canvas follow the handle (H8)', () => {
const hit = marker('anno-a')
const version = store.getState().handleVersion
down(hit, 50, 50)
fireEvent.pointerMove(hit, { clientX: 70, clientY: 50, pointerId: 1 })
fireEvent.pointerMove(hit, {
clientX: 70,
clientY: 50,
pointerId: 1,
buttons: 1,
})
fireEvent.lostPointerCapture(hit, { pointerId: 1 })
fireEvent.pointerUp(hit, { clientX: 70, clientY: 50, pointerId: 1 })
expect(store.getState().handleVersion).toBe(version)
@@ -935,7 +931,12 @@ describe('the drag and the canvas follow the handle (H8)', () => {
const hit = marker('anno-a')
const version = store.getState().handleVersion
down(hit, 50, 50)
fireEvent.pointerMove(hit, { clientX: 70, clientY: 50, pointerId: 1 })
fireEvent.pointerMove(hit, {
clientX: 70,
clientY: 50,
pointerId: 1,
buttons: 1,
})
view.rerender(<AnnotationsTab {...props} readOnly />)
fireEvent.pointerUp(hit, { clientX: 70, clientY: 50, pointerId: 1 })
expect(store.getState().handleVersion).toBe(version)
@@ -1009,10 +1010,10 @@ describe('« Désélectionner » (R1, A6)', () => {
await userEvent.setup().click(button(panel))
const filter = screen.getByLabelText('Filtrer par nom')
fireEvent.change(filter, { target: { value: 'zzz-no-match' } })
fireEvent.click(
screen.getByTestId('annotation-canvas-drawing').querySelector(
'[data-anno-id="anno-a"]',
)!,
pressAt(
screen
.getByTestId('annotation-canvas-drawing')
.querySelector('[data-anno-id="anno-a"]')!,
)
const reopened = await screen.findByTestId('annotation-properties')
await userEvent.setup().click(button(reopened))
@@ -1035,7 +1036,9 @@ describe('« Désélectionner » (R1, A6)', () => {
it('read-only: no « Supprimer », it deselects and focuses the ro- row', async () => {
await mountSpy({ readOnly: true })
const panel = await selectFromList()
expect(within(panel).queryByRole('button', { name: 'Supprimer' })).toBeNull()
expect(
within(panel).queryByRole('button', { name: 'Supprimer' }),
).toBeNull()
await userEvent.setup().click(button(panel))
expect(screen.queryByTestId('annotation-properties')).toBeNull()
const row = document.querySelector(
@@ -1089,9 +1092,13 @@ describe('« Désélectionner » (R1, A6)', () => {
}),
})
const panel = await selectFromList()
await userEvent.setup().click(
within(panel).getByRole('button', { name: 'Remplacer par un polygone' }),
)
await userEvent
.setup()
.click(
within(panel).getByRole('button', {
name: 'Remplacer par un polygone',
}),
)
const open = await screen.findByTestId('annotation-properties')
expect(
within(open).queryByRole('button', { name: 'Désélectionner' }),
@@ -1275,23 +1282,21 @@ describe('a tap on the drawing (D6b)', () => {
expect(fireEvent.keyDown(canvas, { key: 'ArrowLeft' })).toBe(false)
})
it('a pen tap deselects in its own click, like a touch tap', async () => {
it('a pen tap deselects at the pointer-up, like a mouse tap', async () => {
await selected()
const hit = rect()
fireEvent.pointerDown(hit, { ...init(1, 'pen'), clientX: 10, clientY: 10 })
fireEvent.pointerUp(hit, { ...init(1, 'pen'), clientX: 10, clientY: 10 })
expect(isDeselected()).toBe(false)
fireEvent.click(hit)
expect(isDeselected()).toBe(true)
expect(announce).toHaveBeenCalledWith(DESELECTED)
})
it('a pen tap whose click lands on a marker selects that marker', async () => {
it('a pen tap is decided by its press: a click landing on a marker selects nothing', async () => {
await selected({ text: insert(text(), named('anno-b', 90, 90, 3)) })
tap(rect(), { type: 'pen', upOn: marker('anno-b') })
expect(announce).not.toHaveBeenCalled()
expect(marker('anno-b')).toHaveAttribute('data-state', 'current')
expect(marker('anno-a')).not.toHaveAttribute('data-state')
expect(announce).toHaveBeenCalledWith(DESELECTED)
expect(marker('anno-b')).not.toHaveAttribute('data-state')
expect(isDeselected()).toBe(true)
})
it('a hover move after the press does not count as a drag', async () => {
@@ -1312,7 +1317,11 @@ describe('a tap on the drawing (D6b)', () => {
await selected()
fireEvent.pointerDown(rect(), { ...init(), clientX: 10, clientY: 10 })
fireEvent.pointerUp(document.body, { ...init(), clientX: 10, clientY: 10 })
fireEvent.pointerDown(document.body, { ...init(), clientX: 300, clientY: 10 })
fireEvent.pointerDown(document.body, {
...init(),
clientX: 300,
clientY: 10,
})
fireEvent.pointerUp(rect(), { ...init(), clientX: 10, clientY: 10 })
fireEvent.click(rect())
expect(isDeselected()).toBe(false)
@@ -1432,7 +1441,7 @@ describe('a tap on the drawing (D6b)', () => {
expect(isDeselected()).toBe(false)
})
it('a touch tap deselects in its own click, not at the pointer-up', async () => {
it('a touch tap deselects at the pointer-up', async () => {
await selected()
const hit = rect()
fireEvent.pointerDown(hit, {
@@ -1441,18 +1450,42 @@ describe('a tap on the drawing (D6b)', () => {
clientY: 10,
})
fireEvent.pointerUp(hit, { ...init(1, 'touch'), clientX: 10, clientY: 10 })
expect(isDeselected()).toBe(false)
fireEvent.click(hit)
expect(isDeselected()).toBe(true)
})
it('a touch tap whose click lands on a marker (adjustment) selects that marker', async () => {
it('a touch tap is decided by its press: a click adjusted toward a marker selects nothing', async () => {
await selected({ text: insert(text(), named('anno-b', 90, 90, 3)) })
tap(rect(), { type: 'touch', upOn: marker('anno-b') })
expect(announce).not.toHaveBeenCalled()
expect(announce).toHaveBeenCalledWith(DESELECTED)
expect(isDeselected()).toBe(true)
expect(marker('anno-b')).not.toHaveAttribute('data-state')
})
it('a finger drags the selected point (its handle), never a selected zone (A13)', async () => {
const zone = zoneAnnotation({ type: 'polygon', points: triangle })
await selected({
text: insert(text(), { kind: 'annotation', value: zone }),
})
const drag = (el: Element) => {
fireEvent.pointerDown(el, {
...init(1, 'touch'),
clientX: 50,
clientY: 50,
})
fireEvent.pointerMove(el, {
...init(1, 'touch'),
clientX: 70,
clientY: 50,
})
fireEvent.pointerUp(el, { ...init(1, 'touch'), clientX: 70, clientY: 40 })
}
drag(marker('anno-a'))
expect(geometryOf('anno-a')).toMatchObject({ cx: 70, cy: 40 })
tap(marker('zone-a'))
const before = store.getState().documentText
drag(marker('zone-a'))
expect(store.getState().documentText).toBe(before)
expect(isDeselected()).toBe(false)
expect(marker('anno-b')).toHaveAttribute('data-state', 'current')
expect(marker('anno-a')).not.toHaveAttribute('data-state')
})
it('a mouse tap deselects at the pointer-up and swallows the click on a marker', async () => {