fix(editor): return the focus without a scroll; drop an inert tap

Final review M-4 and M-6: the line's « Défaire » focuses the drawing
through focusDrawing (preventScroll), and a mode's end focuses its
entry with preventScroll, so neither scrolls the page (A14).
M-8: the empty tap kept after the removed click was as inert; gone.

Tests removed: in « a mouse tap deselects at the pointer-up », the
second pointerDown/pointerUp on the empty drawing and its repeated
isDeselected assertion (the first tap's assertion covers it).
This commit is contained in:
bchanot committed 2026-11-18 13:12:56 +01:00
1 parent 10a8767527
commit a6685a04e0
3 files changed
+11 -12

No files matched your search

@@ -1,16 +1,15 @@
import type { ReactNode } from 'react'
import { useEditorReadOnly } from '@/editor/editingContext'
import { visibleElement } from '@/editor/focusRequest'
import type {
GestureMessage as Shown,
GestureMessages,
} from '@/editor/annotations/useGestureMessage'
import { focusDrawing } from '@/editor/annotations/deselect'
import { canUndo, useEditorStore } from '@/editor/state/editorStore'
import {
cancelPending,
useAnnotationWork,
} from '@/editor/annotations/workStore'
import { CANVAS_BOX } from '@/editor/useEditorNavigation'
import { useT } from '@/i18n/useT'
const PILL =
@@ -30,8 +29,9 @@ function undoLast(readOnly: boolean): void {
const store = useEditorStore.getState()
if (readOnly || cancelPending() || !canUndo(store)) return
store.undoStep()
// M-4: the undo closes the pill under the focus; the drawing takes it (WCAG 2.4.3).
visibleElement(CANVAS_BOX)?.focus()
// M-4: the undo closes the pill under the focus; the drawing takes it (WCAG 2.4.3),
// without a scroll (A14).
focusDrawing()
}
/**
@@ -1,11 +1,11 @@
import { useEffect, useRef, type Dispatch } from 'react'
import { visibleElement } from '@/editor/focusRequest'
import { CANVAS_BOX } from '@/editor/useEditorNavigation'
import type {
Annotation,
AnatomicalSheetDocument,
} from '@faunosteo/core-wasm/types'
import Button from '@/components/ui/Button'
import { focusDrawing } from '@/editor/annotations/deselect'
import { defaultRadius, type Frame } from '@/editor/annotations/frame'
import {
newPointSize,
@@ -88,8 +88,10 @@ export function useModeFocusReturn(mode: FocusMode) {
const ended = was.current
was.current = mode
if (ended === null || mode !== null || !lost) return
const entry = visibleElement(ENTRY[ended]) ?? visibleElement(CANVAS_BOX)
entry?.focus()
// No scroll either way (A14): the strip's command, else the drawing.
const entry = visibleElement(ENTRY[ended])
if (entry) entry.focus({ preventScroll: true })
else focusDrawing()
}, [mode])
}
@@ -1553,14 +1553,11 @@ describe('a tap on the drawing (D6b)', () => {
})
// Final review M-8: since T2 a `click` on the canvas does nothing, so the click this test
// fired on a marker could not change the outcome; it is gone, the taps are the test.
it('a mouse tap deselects at the pointer-up; another tap on the empty drawing keeps it so', async () => {
// fired on a marker (and the empty tap before it) could not change the outcome: gone.
it('a mouse tap deselects at the pointer-up', async () => {
await selected({ text: insert(text(), named('anno-b', 90, 90, 3)) })
tap(rect(), { upOn: rect() })
expect(isDeselected()).toBe(true)
fireEvent.pointerDown(rect(), { ...init(), clientX: 10, clientY: 10 })
fireEvent.pointerUp(rect(), { ...init(), clientX: 10, clientY: 10 })
expect(isDeselected()).toBe(true)
})
it('a press on a polygon vertex handle outside its fill deselects (documented)', async () => {