From d05c3fe34e50f4f4a46c8412df34d7146bb2bab1 Mon Sep 17 00:00:00 2001 From: bchanot Date: Mon, 23 Nov 2026 16:57:34 +0100 Subject: [PATCH] test(editor): double click opens an access view, focus kept --- .../editor/annotations/useViewNavigation.ts | 14 ++++++++++++-- .../unit/editor-view-navigation.test.tsx | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/apps/app/src/editor/annotations/useViewNavigation.ts b/apps/app/src/editor/annotations/useViewNavigation.ts index be6a3ea7..e2ce2c61 100644 --- a/apps/app/src/editor/annotations/useViewNavigation.ts +++ b/apps/app/src/editor/annotations/useViewNavigation.ts @@ -1,6 +1,7 @@ import type { Dispatch } from 'react' import type { Scene } from '@/components/editor/annotations/EditableAnnotations' -import { guardDrawing } from './drawingGuard' +import { flushSync } from 'react-dom' +import { guardDrawing, focusPressedIfLost } from './drawingGuard' import { guardedPress } from './guardedPress' import type { UiAction } from './uiState' @@ -12,6 +13,15 @@ export interface ViewNavigation { goToParent: (control: HTMLElement | null) => void } +/** No control was pressed: the marker unmounts, the focus returns to the drawing. */ +function showFromDrawing(show: () => void) { + flushSync(show) + const viewport = document.querySelector( + '[data-drawing-column] [data-testid="annotation-canvas"]', + ) + if (viewport) focusPressedIfLost(viewport) +} + /** * The two ways to reach another view from the drawing, « Vue parente » and « Ouvrir la * vue » (D14). The view stays a UI state: no history entry is pushed (D15). @@ -25,7 +35,7 @@ export function useViewNavigation( const openView = (viewId: string, control: HTMLElement | null) => { const show = () => dispatch({ type: 'view', viewId }) if (control) guardedPress(control, show) - else if (guardDrawing(show)) show() + else if (guardDrawing(show)) showFromDrawing(show) } return { openView, diff --git a/apps/app/tests/unit/editor-view-navigation.test.tsx b/apps/app/tests/unit/editor-view-navigation.test.tsx index c2fa73e6..0b1f07f9 100644 --- a/apps/app/tests/unit/editor-view-navigation.test.tsx +++ b/apps/app/tests/unit/editor-view-navigation.test.tsx @@ -174,6 +174,25 @@ describe('« Ouvrir la vue » and the second click', () => { expect(screen.queryByRole('dialog')).toBeNull() }) + it('a double click on an unselected access opens its view, focus kept', async () => { + await mount() + await screen.findByRole('list', { name: 'Annotations de la vue' }) + pressAt(marker('l'), 50, 50) + pressAt(marker('l'), 50, 50) + await waitFor(() => shown('Tête')) + expect(screen.queryByRole('dialog')).toBeNull() + expect(document.activeElement).not.toBe(document.body) + }) + + it('a double click on an unselected point opens its properties', async () => { + await mount() + await screen.findByRole('list', { name: 'Annotations de la vue' }) + pressAt(marker('p'), 50, 50) + pressAt(marker('p'), 50, 50) + expect(await screen.findByRole('dialog')).toBeInTheDocument() + shown('Vue principale') + }) + it('a second click on a selected point still opens its properties', async () => { await mount() await selectRow(0)