feat(editor): vertex handles, insert and remove, zone move, redraw

U2 Task 5. A selected polygon gets its vertex, « + » and « − » handles
(R-9, hidden « + » under two hit radii, R-18 zoom hint in the strip),
the handle cap at 40 (R-7), vertex drag and keys, the move mode on the
zone or the chosen vertex, « Redessiner » as a redraw mode kept in step
with its tracing (R-12 guard, R-13 drop), close radius in CSS px
(R-11). The numeric group leaves the properties panel (D1).

Removed or rewritten assertions (numeric group -> replacement):
- tab « shows its exact stored numbers » (Centre x field) -> the overlay
  selection circle's cx attribute, same exact value.
- tab « a numeric edit » x3 -> « an edit on the drawing »: Enter on the
  handle without a step commits nothing, a step + Enter commits once;
  a refused handle drag keeps the stored shape then a drag inside the
  frame repairs it (issues gone); Escape drops a pending series.
- tab C26 « Centre x 15 » -> overlay cx 15.
- tab C32 unmeasured « Centre x as text » -> no handle, no field.
- tab « adds and removes a vertex as part of the whole group » -> « + »
  then « − » on the drawing; « never offers to remove below three » ->
  « − » aria-disabled at 3.
- tab H8 « refused Remplacer drops the tracing » -> keeps it open with
  « Fermeture refusée » (board 33 A); « refused vertex add/remove stay
  non appliqué » -> a refused vertex drag restores the shape exactly.
- tab Désélectionner and D6b (typed Centre x committed, refused, undone)
  x6 and strip « a new commit replaces the message » -> the same with
  the Nom (FR) field (a blank name is the refused value).
- focus-request « Centre x 20 » -> overlay cx 20.
- escape « strip commands keep their Escape » -> a redraw: Escape on the
  strip or the box cancels it (R-12 row 4); kept for a new zone tracing.
- keep-alive « Remplacer tracing kept across Aller à » -> ended by a tab
  when empty, asked once a vertex is placed (R-12).
- e2e annotations: numeric cx edit + undo/redo -> handle keys + undo/
  redo; jitter/drag and Task 4 point reads -> overlay attributes (the
  stored place during the mode -> overlay-old-place); keyboard-only cy
  and vertex x typed -> handle and vertex keys.
- e2e deselect: Centre x typed/refused/committed -> Nom (FR).
- e2e geometry, shell-crossing: Centre x/cy reads -> overlay attributes.
- e2e journey: cx +3 and vertex x +4 typed -> 3 and 4 arrow steps + Enter;
  a far typed value + revert -> a far handle drag refused.
- e2e equine latency: typed cx rounds -> handle arrow + Enter rounds.
This commit is contained in:
bchanot committed 2026-11-17 20:24:49 +01:00
1 parent ba8e766fe8
commit 6211046537
44 files changed
+3790 -1050

No files matched your search

+68 -41
View File
@@ -10,12 +10,10 @@ import { updateGeometry, type CommitContext } from './annotationCommit'
import { pendingForClick, type NewKind } from './creation'
import { round2, type Frame, type XY } from './frame'
import { newPointSize } from './pointSize'
import { endMode, useAnnotationWork } from './workStore'
import type { ToolId, Tracing, UiAction, UiState } from './uiState'
import type { GestureMessages } from './useGestureMessage'
/** A click on the first vertex closes the tracing when within this share of F's span. */
const CLOSE_SHARE = 0.015
const TOOL_TARGET: Record<Exclude<ToolId, 'select'>, NewKind> = {
point: 'point',
zone: 'zone',
@@ -35,47 +33,56 @@ export interface PlacementInput {
const asPoint = (at: XY): Point => [round2(at.x), round2(at.y)]
function nearFirstVertex(tracing: Tracing, at: XY, frame: Frame): boolean {
/** R-11: `reach` is the closing radius of the pointer, in drawing units. */
function nearFirstVertex(tracing: Tracing, at: XY, reach: number): boolean {
const first = tracing.points[0]
if (!first || tracing.points.length < 3) return false
const reach = CLOSE_SHARE * Math.max(frame.w, frame.h)
return Math.hypot(first[0] - at.x, first[1] - at.y) <= reach
}
/**
* What closing a tracing does: a new zone or link becomes the pending element; a polygon
* replacing a geometry is committed at once under `accept`, and a refusal drops the
* tracing with the core's message (the annotation is unchanged).
* A redraw's close commits the polygon at once. The mode leaves first, so the commit is
* never said as an abandoned redraw (R-13); a refusal brings it back and keeps the
* tracing open with the core's message (board 33 A).
*/
export function closingActions(
tracing: Tracing | null,
doc: AnatomicalSheetDocument,
context: CommitContext,
): UiAction[] {
if (!tracing || tracing.points.length < 3) return []
const polygon = { type: 'polygon' as const, points: tracing.points }
if (tracing.target !== 'replace') {
const pending = { kind: tracing.target, geometry: polygon }
return [{ type: 'pending_new', pending }]
}
function closeRedraw(input: PlacementInput, tracing: Tracing): void {
const { doc, context, dispatch } = input
const annotation = doc.annotations.find((a) => a.id === tracing.annotationId)
if (!annotation) return [{ type: 'trace_cancel' }]
if (!annotation) return dispatch({ type: 'trace_cancel' })
const held = useAnnotationWork.getState().mode
endMode()
const polygon = { type: 'polygon' as const, points: tracing.points }
const result = updateGeometry(annotation, polygon, context)
if (result.ok) return [{ type: 'select', id: annotation.id }]
return [
{ type: 'trace_cancel' },
{ type: 'hint', hint: result.messages.join(' ') },
]
if (!result.ok) {
useAnnotationWork.setState({ mode: held })
return dispatch({ type: 'hint', hint: result.messages.join(' ') })
}
dispatch({ type: 'select', id: annotation.id })
const text = context.t(
`editor.annotations.message.redrawn.${annotation.kind}`,
)
input.message.show(text, { undo: true, tone: 'info' })
}
/** Tracing with the zone and link tools: vertices, closing, Enter, Backspace and Escape. */
function tracingActions(input: PlacementInput) {
const { ui, dispatch, frame } = input
const closeTracing = () =>
closingActions(ui.tracing, input.doc, input.context).forEach(dispatch)
const trace = (tool: Exclude<ToolId, 'select' | 'point'>, at: XY) => {
if (!frame) return
if (ui.tracing && nearFirstVertex(ui.tracing, at, frame)) {
const { ui, dispatch } = input
const closeTracing = () => {
const tracing = ui.tracing
if (!tracing || tracing.points.length < 3) return
if (tracing.target === 'replace') return closeRedraw(input, tracing)
const pending = {
kind: tracing.target,
geometry: { type: 'polygon' as const, points: tracing.points },
}
dispatch({ type: 'pending_new', pending })
}
const trace = (
tool: Exclude<ToolId, 'select' | 'point'>,
at: XY,
reach: number,
) => {
if (ui.tracing && nearFirstVertex(ui.tracing, at, reach)) {
return closeTracing()
}
if (!ui.tracing)
@@ -97,14 +104,25 @@ function tracingActions(input: PlacementInput) {
return { closeTracing, trace, onTraceKey }
}
/** A move (drag, move mode, arrow keys) or a size change of the selection. */
export type GeometryChange = 'move' | 'size'
/**
* A move (drag, move mode, arrow keys) or a size change of the selection, a vertex
* moved, added or removed.
*/
export type GeometryChange = 'move' | 'size' | 'vertex' | 'insert' | 'remove'
const KEPT: Record<Exclude<GeometryChange, 'move'>, string> = {
size: 'resized',
vertex: 'vertex_moved',
insert: 'vertex_added',
remove: 'vertex_removed',
}
/** The message keys of a kept and of a refused change. */
function changeKeys(change: GeometryChange, kind: Annotation['kind']) {
return change === 'size'
? { kept: 'resized', refused: 'size_refused' }
: { kept: `moved.${kind}`, refused: 'move_refused' }
const kept = change === 'move' ? `moved.${kind}` : KEPT[change]
if (change === 'size') return { kept, refused: 'size_refused' }
const moved = change === 'move' || change === 'vertex'
return { kept, refused: moved ? 'move_refused' : 'edit_refused' }
}
/**
@@ -112,24 +130,32 @@ function changeKeys(change: GeometryChange, kind: Annotation['kind']) {
* with the refused place drawn (the shape stays where it was).
*/
function dropAction({ doc, context, message, dispatch }: PlacementInput) {
return (id: string, geometry: Geometry, change: GeometryChange = 'move') => {
return (
id: string,
geometry: Geometry,
change: GeometryChange = 'move',
): boolean => {
const annotation = doc.annotations.find((a) => a.id === id)
if (!annotation) return
if (!annotation) return false
const keys = changeKeys(change, annotation.kind)
const result = updateGeometry(annotation, geometry, context)
if (result.ok) {
// A kept move ends any refusal the strip still shows.
dispatch({ type: 'hint', hint: null })
const text = context.t(`editor.annotations.message.${keys.kept}`)
return message.show(text, { undo: true, tone: 'info' })
message.show(text, { undo: true, tone: 'info' })
return true
}
const text = context
.t(`editor.annotations.message.${keys.refused}`)
.replace('{text}', () => result.messages.join(' '))
message.show(text, { undo: false, tone: 'error', place: geometry })
return false
}
}
export type Drop = ReturnType<typeof dropAction>
/**
* What a click, a key or a drop does with the current tool. Every geometry it proposes is
* arithmetic over F; the core decides at « Créer » or at the commit of an existing one.
@@ -139,9 +165,10 @@ export function usePlacement(input: PlacementInput) {
const t = useT()
const tracing = tracingActions(input)
const { ui, dispatch, frame } = input
const onPlace = (at: XY) => {
/** `reach`: the pointer's closing radius in drawing units (R-11). */
const onPlace = (at: XY, reach: number) => {
if (ui.tool === 'zone' || ui.tool === 'link')
return tracing.trace(ui.tool, at)
return tracing.trace(ui.tool, at, reach)
if (ui.tool !== 'point' || !frame) return
const { doc, viewId } = input
const size = newPointSize(doc.annotations, viewId, frame, ui.size)