From a6685a04e0e3c49c74fa73c8639fa1ff2c7a336a Mon Sep 17 00:00:00 2001 From: bchanot Date: Wed, 18 Nov 2026 13:12:56 +0100 Subject: [PATCH] fix(editor): return the focus without a scroll; drop an inert tap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- .../src/components/editor/annotations/GestureMessage.tsx | 8 ++++---- .../src/components/editor/annotations/PointCommands.tsx | 8 +++++--- apps/app/tests/unit/editor-annotations-tab.test.tsx | 7 ++----- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/apps/app/src/components/editor/annotations/GestureMessage.tsx b/apps/app/src/components/editor/annotations/GestureMessage.tsx index 1f125710..efdac5fd 100644 --- a/apps/app/src/components/editor/annotations/GestureMessage.tsx +++ b/apps/app/src/components/editor/annotations/GestureMessage.tsx @@ -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() } /** diff --git a/apps/app/src/components/editor/annotations/PointCommands.tsx b/apps/app/src/components/editor/annotations/PointCommands.tsx index cb078edd..2f8523ac 100644 --- a/apps/app/src/components/editor/annotations/PointCommands.tsx +++ b/apps/app/src/components/editor/annotations/PointCommands.tsx @@ -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]) } diff --git a/apps/app/tests/unit/editor-annotations-tab.test.tsx b/apps/app/tests/unit/editor-annotations-tab.test.tsx index 843553e3..4fd4031c 100644 --- a/apps/app/tests/unit/editor-annotations-tab.test.tsx +++ b/apps/app/tests/unit/editor-annotations-tab.test.tsx @@ -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 () => {