diff --git a/apps/app/e2e/shell/editor-zones.spec.ts b/apps/app/e2e/shell/editor-zones.spec.ts index db51a9fc..f04e05ac 100644 --- a/apps/app/e2e/shell/editor-zones.spec.ts +++ b/apps/app/e2e/shell/editor-zones.spec.ts @@ -197,10 +197,12 @@ test.describe('editor zones on the drawing (U2 Task 5)', () => { expect(await count(page)).toBe(stored.length - 1) await undoTo(page, () => shownPoints(page), stored) + // The undo cleared the choice, the focus stayed: Backspace acts on that same handle. + await page.keyboard.press('Backspace') + expect(await count(page)).toBe(stored.length - 1) + await undoTo(page, () => shownPoints(page), stored) + // « + » adds after the focused vertex, as Insert, the canvas zoom untouched; undone. - // The undo cleared the choice but left the focus: moving it chooses again. - await handle(page, 'Sommet 2 de Vertèbres thoraciques').focus() - await handle(page, 'Sommet 3 de Vertèbres thoraciques').focus() const drawing = page.getByTestId('annotation-canvas-drawing').locator('..') const framed = () => drawing.evaluate((el) => getComputedStyle(el).transform) diff --git a/apps/app/src/editor/annotations/useZoneEdit.ts b/apps/app/src/editor/annotations/useZoneEdit.ts index 31600ce7..edf4f828 100644 --- a/apps/app/src/editor/annotations/useZoneEdit.ts +++ b/apps/app/src/editor/annotations/useZoneEdit.ts @@ -120,16 +120,22 @@ const REMOVE_KEYS = ['Delete', 'Backspace'] * Insert or « + » adds after the chosen vertex, Delete or Backspace removes it (Mac keyboards * have no Insert and Delete is Backspace; « + » is the drawn « + », whatever the layout). */ -function editKey(input: ZoneEditInput, event: KeyboardEvent): void { - event.preventDefault() +function editKey( + input: ZoneEditInput, + index: number, + event: KeyboardEvent, +): void { // Final review I-1: a move mode changes the position only, as the press machine does. if (inMoveMode()) return + event.preventDefault() // I-1: arrow steps still pending are committed first; the change applies to that place. commitKeys(input) const id = input.target?.id - const chosen = id ? freshChosen(id) : null - if (INSERT_KEYS.includes(event.key) && chosen !== null) - insertAfter(input, chosen) + if (!id) return + // The focused handle is the vertex meant, even if an undo cleared the choice (focus alone + // does not fire again). + if (freshChosen(id) !== index) chooseVertex(id, index) + if (INSERT_KEYS.includes(event.key)) insertAfter(input, index) if (REMOVE_KEYS.includes(event.key)) deleteChosen(input) } @@ -144,7 +150,7 @@ function vertexKey(input: ZoneEditInput, index: number, event: KeyboardEvent) { return inMoveMode() ? input.confirmMove() : commitKeys(input) } if (INSERT_KEYS.includes(event.key) || REMOVE_KEYS.includes(event.key)) - editKey(input, event) + editKey(input, index, event) } /** Enter or Space on a « + » or on the « − » bubble is its click. */ diff --git a/apps/app/tests/unit/editor-zone-edit.test.tsx b/apps/app/tests/unit/editor-zone-edit.test.tsx index f4b85adc..7dccf5aa 100644 --- a/apps/app/tests/unit/editor-zone-edit.test.tsx +++ b/apps/app/tests/unit/editor-zone-edit.test.tsx @@ -223,7 +223,7 @@ describe('a vertex (R-9)', () => { ).toBeNull() void bubble const after = depth() - fireEvent.keyDown(vertex(2), { key: 'Delete' }) + // (A vertex key acts on its own handle, so it is not a stale case; only the bubble is.) // A press where the bubble was reaches what is there now: a bubble still shown, else the // box (which deselects). pressAt(liveBubbleOrCanvas(), 50, 20) @@ -254,6 +254,25 @@ describe('a vertex (R-9)', () => { expect(depth()).toBe(before + 2) }) + it('Backspace, undo, Backspace on the same focused vertex deletes again; so does « + »', async () => { + await mount(squareText()) + render() + await select() + vertex(2).focus() + fireEvent.keyDown(vertex(2), { key: 'Backspace' }) + expect(pointsOf('z')).toHaveLength(3) + fireEvent.keyDown(document.body, { key: 'z', ctrlKey: true }) + expect(pointsOf('z')).toEqual(SQUARE) + expect(chosen()).toBeNull() + fireEvent.keyDown(vertex(2), { key: 'Backspace' }) + expect(pointsOf('z')).toHaveLength(3) + fireEvent.keyDown(document.body, { key: 'z', ctrlKey: true }) + expect(chosen()).toBeNull() + fireEvent.keyDown(vertex(2), { key: '+' }) + expect(pointsOf('z')).toHaveLength(5) + expect(chosen()).toMatchObject({ vertex: 2 }) + }) + it('Backspace at three vertices keeps them with the reason; « + » needs no drawn « + »', async () => { await mount(squareText(SQUARE.slice(0, 3))) await select() @@ -793,7 +812,6 @@ describe('fix round 1: no lost series, no lost focus, no stale « − »', () => chosen: { annotationId: 'z', vertex: 1, base: 'an older text' }, }), ) - fireEvent.keyDown(vertex(2), { key: 'Delete' }) pressAt(liveBubbleOrCanvas(), 80, 10) expect(pointsOf('z')).toEqual(SQUARE) expect(depth()).toBe(before) @@ -908,6 +926,14 @@ describe('the zoom hint for short segments (R-18, D2)', () => { ) }) + it('« + » on the canvas box itself still zooms', async () => { + await mount(squareText(SHORT)) + await select() + fireEvent.keyDown(screen.getByTestId('annotation-canvas'), { key: '+' }) + fireEvent.keyDown(screen.getByTestId('annotation-canvas'), { key: '+' }) + await waitFor(() => expect(plus(1)).toBeInTheDocument()) + }) + it('a refusal takes its place while shown', async () => { await mount(squareText(SHORT)) await select() @@ -1093,6 +1119,8 @@ describe('final review I-1: a redo or a handle key never drops pending work', () fireEvent.keyDown(minus(3), { key: 'Enter' }) fireEvent.keyDown(vertex(3), { key: 'Insert' }) fireEvent.keyDown(vertex(3), { key: 'Delete' }) + expect(fireEvent.keyDown(vertex(3), { key: 'Backspace' })).toBe(true) + expect(fireEvent.keyDown(vertex(3), { key: '+' })).toBe(true) fireEvent.keyDown(plus(2), { key: 'Enter' }) expect(pointsOf('z')).toEqual(SQUARE) expect(depth()).toBe(before)