Files
faunosteo/apps/app/src/editor/annotations/zoneEdit.ts
T
bchanot e596e0765e fix(editor): no lost series, tap click absorbed, focus kept on handles
Task 5 review fix round 1.
- I-1: Insert and Delete on a vertex commit pending arrow steps first,
  then act on the stored polygon (read from the store, not the render).
- I-2: deselect commits a handle's pending series before the handle
  unmounts (commitFocusedSeries, no reliance on blur at removal).
- I-3: a touch or pen tap absorbs the click the browser synthesises at
  its place, once, within 400 ms and 8 px; mouse and later clicks pass.
  Scroll anchoring is off while the editor shows: the deselect's panel
  swap scrolled the drawing under the finger. editor-deselect step c is
  back at the page's end, and asserts the drawing does not move.
- I-4, M-2: the double-click and undo tests press what is there now;
  a hand-set stale chosen vertex removes nothing.
- I-5: editor-zones undos, the vertex choice and the refused-trace
  clicks run under expectNoShift; new e2e for I-2.
- M-1: Delete on the last vertex and Enter on « − » keep the focus on a
  vertex (the next one is chosen).
- M-4: the strip notice comment names R-18. M-5: the tracing carries a
  `refused` flag; only a refused close titles « Fermeture refusée ».
- M-7: TODO lines (bubble size shortcut, scroll-padding-top, scroll
  clamp at the page's end).

Rewritten assertions: zone-edit « − » double click and undo-then-« − »
pressed the detached bubble -> press the live bubble or the box at the
same place. editor-deselect step c: scroll-to-top removed, drawing y
asserted unchanged. editor-geometry: scroll-to-top kept with the clamp
named (reported, TODO). editor-zones and editor-journey: comment says
the scroll-to-top undoes Playwright's own auto-scroll.
2026-11-17 21:04:23 +01:00

35 lines
1.6 KiB
TypeScript

import type { Geometry, Point } from '@faunosteo/core-wasm/types'
import { useEditorStore } from '../state/editorStore'
import { HANDLE_CAP } from './polygonEdit'
import { useAnnotationWork } from './workStore'
/** A polygon's vertices when it gets handles (R-7: at most HANDLE_CAP), else null. */
export function handledPoints(geometry: Geometry | null): Point[] | null {
if (geometry?.type !== 'polygon') return null
return geometry.points.length > HANDLE_CAP ? null : geometry.points
}
/** The vertex `vertex` of `annotationId` is chosen, stamped with the current text (R-13). */
export function chooseVertex(annotationId: string, vertex: number): void {
const base = useEditorStore.getState().documentText
useAnnotationWork.setState({ chosen: { annotationId, vertex, base } })
}
/** The chosen vertex of `annotationId`, only when it was chosen on the current text. */
export function freshChosen(annotationId: string): number | null {
const { chosen } = useAnnotationWork.getState()
if (chosen?.annotationId !== annotationId) return null
const current = useEditorStore.getState().documentText
return chosen.base === current ? chosen.vertex : null
}
/**
* The polygon of `annotationId` in the current document, read from the store: a commit
* made earlier in the same event (a pending series committed first) counts.
*/
export function currentPoints(annotationId: string): Point[] | null {
const doc = useEditorStore.getState().previewState?.document
const geometry = doc?.annotations.find((a) => a.id === annotationId)?.geometry
return geometry?.type === 'polygon' ? geometry.points : null
}