diff --git a/apps/app/src/components/editor/annotations/AnnotationList.tsx b/apps/app/src/components/editor/annotations/AnnotationList.tsx index 4ed4237f..4c1b9b1b 100644 --- a/apps/app/src/components/editor/annotations/AnnotationList.tsx +++ b/apps/app/src/components/editor/annotations/AnnotationList.tsx @@ -15,7 +15,7 @@ const ROW = /** What a row does: a click or Enter selects (A1); Enter on the selected row opens. */ interface RowActions { selectedId: string | null - onSelect: (id: string) => void + onSelect: (id: string, row: HTMLElement) => void onOpen: (id: string) => void } @@ -58,7 +58,9 @@ function Row({ event.preventDefault() if (!event.repeat) actions.onOpen(annotation.id) }} - onClick={() => actions.onSelect(annotation.id)} + onClick={(event) => + actions.onSelect(annotation.id, event.currentTarget) + } className={ROW} > diff --git a/apps/app/src/components/editor/annotations/EditableAnnotations.tsx b/apps/app/src/components/editor/annotations/EditableAnnotations.tsx index 04a4f2e3..5b981bfe 100644 --- a/apps/app/src/components/editor/annotations/EditableAnnotations.tsx +++ b/apps/app/src/components/editor/annotations/EditableAnnotations.tsx @@ -216,16 +216,21 @@ function useHeldHistoryMessage( const press = useAnnotationWork((s) => s.historyPress) const seen = useRef(press) const visible = usePlaceVisible() + // `show` and `t` are rebuilt per render: the effect reads the latest, runs on a new press. + const latest = useRef({ message, t, visible }) + useEffect(() => { + latest.current = { message, t, visible } + }) useEffect(() => { if (press === seen.current) return seen.current = press - if (press && visible) { - message.show(t(`editor.history.hold_${press.reason}`), { + const now = latest.current + if (press && now.visible) { + now.message.show(now.t(`editor.history.hold_${press.reason}`), { undo: false, tone: 'info', }) } - // eslint-disable-next-line react-hooks/exhaustive-deps -- show is rebuilt per render }, [press]) } @@ -304,9 +309,9 @@ const guarded = (action: () => void) => () => { } /** - * A tool or a view chip, guarded as above. Pressed with the focus still on a handle (Safari + * A tool, a view chip or an overview row, guarded as above. Pressed with the focus still on a handle (Safari * focuses no clicked button), the change unmounts that handle: the focus then lands on the - * pressed button, where the keyboard's press leaves it, never on `body` (rev 4 M-4). + * pressed control, where the keyboard's press leaves it, never on `body` (rev 4 M-4). */ function guardedPress(button: HTMLElement, action: () => void) { if (!guardDrawing(action)) return @@ -497,12 +502,12 @@ function SidePanel({ scene }: { scene: Scene }) { onFilter={(term) => dispatch({ type: 'filter', term })} // The column stays shown during a selection (A3): a row or a view that would drop // a started move or redraw asks first (R-12). - onSelectView={(id) => - guarded(() => dispatch({ type: 'view', viewId: id }))() + onSelectView={(id, row) => + guardedPress(row, () => dispatch({ type: 'view', viewId: id })) } selectedId={scene.selected?.id ?? null} - onSelectAnnotation={(id) => - guarded(() => dispatch({ type: 'select', id }))() + onSelectAnnotation={(id, row) => + guardedPress(row, () => dispatch({ type: 'select', id })) } onOpenAnnotation={(id) => scene.onOpen(id, 'drawing')} onOpenSection={scene.onOpenSection} diff --git a/apps/app/src/components/editor/annotations/OverviewPanel.tsx b/apps/app/src/components/editor/annotations/OverviewPanel.tsx index 968eaf9c..417277bc 100644 --- a/apps/app/src/components/editor/annotations/OverviewPanel.tsx +++ b/apps/app/src/components/editor/annotations/OverviewPanel.tsx @@ -32,10 +32,11 @@ export interface OverviewPanelProps { /** The « Filtrer par nom » term, held by the parent so a selection does not lose it. */ filter: string onFilter: (term: string) => void - onSelectView: (viewId: string) => void + /** `row` is the pressed row: the focus may land on it (Safari, see `guardedPress`). */ + onSelectView: (viewId: string, row: HTMLElement) => void /** The selection, marked in the list (A3). */ selectedId: string | null - onSelectAnnotation: (annotationId: string) => void + onSelectAnnotation: (annotationId: string, row: HTMLElement) => void /** Enter on the selected row: its properties dialog (A1). */ onOpenAnnotation: (annotationId: string) => void onOpenSection: (section: AnnotationSection, opener: HTMLElement) => void @@ -71,7 +72,7 @@ function ViewRow({ view: SheetView current: boolean count: number - onSelect: () => void + onSelect: (row: HTMLElement) => void }) { const t = useT() const plural = usePlural() @@ -81,7 +82,7 @@ function ViewRow({