diff --git a/apps/app/e2e/shell/editor-annotations.spec.ts b/apps/app/e2e/shell/editor-annotations.spec.ts index fb80c6f1..2afefcdc 100644 --- a/apps/app/e2e/shell/editor-annotations.spec.ts +++ b/apps/app/e2e/shell/editor-annotations.spec.ts @@ -459,7 +459,13 @@ test.describe('editor annotations (A3)', () => { const right = button(page, 'editor.annotations.move.right') await expect(right).toBeVisible() await expectAccessible(page, 'the move mode') - for (let step = 0; step < 3; step++) await right.click() + await expectNoShift( + page, + async () => { + for (let step = 0; step < 3; step++) await right.click() + }, + swaps, + ) await expect(cx).toHaveValue(String(x0)) await expectNoShift( page, @@ -488,13 +494,20 @@ test.describe('editor annotations (A3)', () => { const fit = (await hit.boundingBox())! // R-9: a 10 px hit radius with a mouse (Chromium desktop has a fine pointer). expect(Math.abs(fit.width - 20)).toBeLessThan(2) + // The drawing's own scale: the measure below waits for the zoom to land. + const transform = () => + page + .getByTestId('annotation-canvas') + .evaluate( + (box) => (box.firstElementChild as HTMLElement).style.transform, + ) + const before = await transform() await page .getByRole('button', { name: dict['catalogue.zoom.in'] }) .click() - await expect - .poll(async () => Math.round((await hit.boundingBox())!.width)) - .toBeLessThan(22) - expect(Math.abs((await hit.boundingBox())!.width - 20)).toBeLessThan(2) + await expect.poll(transform).not.toBe(before) + const zoomed = (await hit.boundingBox())! + expect(Math.abs(zoomed.width - 20)).toBeLessThan(2) }) test('the editor keeps a stable scrollbar gutter; the dashboard does not', async ({ diff --git a/apps/app/src/components/editor/annotations/EditableAnnotations.tsx b/apps/app/src/components/editor/annotations/EditableAnnotations.tsx index 384625d1..2102c5d6 100644 --- a/apps/app/src/components/editor/annotations/EditableAnnotations.tsx +++ b/apps/app/src/components/editor/annotations/EditableAnnotations.tsx @@ -173,7 +173,11 @@ type Work = ReturnType function useModeFollowsSelection(selectedId: string | null) { const modeId = useAnnotationWork((s) => s.mode?.annotationId ?? null) useEffect(() => { - if (modeId !== null && modeId !== selectedId) endMode() + if (modeId === null || modeId === selectedId) return + const { mode } = useAnnotationWork.getState() + endMode() + // Never silent (R-13): a started move that ends this way is said. + if (mode?.started) useAnnotationWork.setState({ dropped: mode.kind }) }, [modeId, selectedId]) } diff --git a/apps/app/src/components/editor/annotations/HandleLayer.tsx b/apps/app/src/components/editor/annotations/HandleLayer.tsx index 5b467c99..3a687250 100644 --- a/apps/app/src/components/editor/annotations/HandleLayer.tsx +++ b/apps/app/src/components/editor/annotations/HandleLayer.tsx @@ -8,7 +8,10 @@ import { } from 'react' import type { Geometry } from '@faunosteo/core-wasm/types' import { parseFrame } from '@/editor/annotations/frame' -import { handleSizes } from '@/editor/annotations/handleSize' +import { + useHandleSizes, + type HandleSizes, +} from '@/editor/annotations/handleSize' import { useAnnotationWork } from '@/editor/annotations/workStore' /** The selected point (or link circle) whose handle the layer draws. */ @@ -40,7 +43,10 @@ function useBoxSize(svg: RefObject) { setSize({ w: element.clientWidth || 0, h: element.clientHeight || 0 }) read() if (typeof ResizeObserver === 'undefined') return - const observer = new ResizeObserver(read) + const observer = new ResizeObserver(([entry]) => { + const box = entry?.contentRect + if (box) setSize({ w: box.width, h: box.height }) + }) observer.observe(element) return () => observer.disconnect() }, [svg]) @@ -72,6 +78,7 @@ function unitsPerPx( export default function HandleLayer(props: HandleLayerProps) { const svg = useRef(null) const unit = unitsPerPx(props.viewBox, useBoxSize(svg), props.scale) + const sizes = useHandleSizes() return ( {props.handle && ( - + )} ) @@ -92,19 +104,26 @@ function PointHandleShape({ unit, onKeyDown, onBlur, -}: HandleLayerProps & { handle: PointHandle; unit: number }) { + sizes, +}: HandleLayerProps & { + handle: PointHandle + unit: number + sizes: HandleSizes +}) { const preview = useAnnotationWork((s) => s.preview?.annotationId === handle.annotationId ? s.preview.geometry : null, ) const shown = preview ?? handle.stored if (shown.type !== 'circle') return null - const r = Math.max(shown.r, handleSizes().hit * unit) + const r = Math.max(shown.r, sizes.hit * unit) return ( - {annotation.kind === 'point' && } +