fix(editor): creation question lapses, guard sites and flip tested

The creation's « Abandonner la création ? » no longer outlives it:
« Replacer le point », « Reprendre le tracé », « Créer » (« Utiliser
cette position » included) and « Annuler le tracé » clear a question
still open, which would otherwise reappear over the page. Locals
trimmed in the creation dialog and the tracing actions (5 max).

Tests added (no assertion removed): the two lapses (RED without the
fix, GREEN with it); a view chip and a tool ask during a tracing; the
mode flip keeps the dialog, its form and the ghost; a history jump out
of the editor waits for the creation's question; e2e: « Reprendre le
tracé » and « Revenir aux propriétés » under expectNoShift at 1 024,
1 180 and 1 280 px, the strip's last command inside it, axe on the
resumed state.
This commit is contained in:
bchanot committed 2026-11-17 23:41:24 +01:00
1 parent 4d2c64f57f
commit fe333c2bbd
6 files changed
+219 -37

No files matched your search

@@ -15,6 +15,15 @@ export interface CreationStart {
const creation = () => useAnnotationWork.getState().creation
/**
* The creation's own question (« Abandonner la création ? ») lapses once the creation ends
* or its dialog hides: it would otherwise reappear over the page with nothing to ask.
*/
const lapsed = () => {
const { question } = useAnnotationWork.getState()
return question?.work === 'creation' ? null : question
}
function patch(change: Partial<Creation>): void {
const current = creation()
if (current)
@@ -93,11 +102,13 @@ export function closeTrace(): boolean {
/** « Reprendre le tracé »: the dialog hides, the vertices and the form are kept. */
export function resumeTrace(): void {
useAnnotationWork.setState({ question: lapsed() })
patch({ closed: false, dialog: false, resumed: true })
}
/** « Replacer le point »: the dialog hides; the next click moves the ghost. */
export function replacePoint(): void {
useAnnotationWork.setState({ question: lapsed() })
patch({ dialog: false, resumed: true })
}
@@ -125,12 +136,16 @@ export function setCorrection(correction: Correction | null): void {
/** « Abandonner », or a guard's « Abandonner »: nothing of the creation is left. */
export function dropCreation(): void {
useAnnotationWork.setState({ creation: null })
useAnnotationWork.setState({ creation: null, question: lapsed() })
}
/** « Créer » succeeded: the creation ends, the drawing selects `id` (A7). */
export function finishCreation(id: string, kind: NewKind): void {
useAnnotationWork.setState({ creation: null, created: { id, kind } })
useAnnotationWork.setState({
creation: null,
created: { id, kind },
question: lapsed(),
})
}
/** The open tracing of a new shape on `viewId`, as the drawing reads a tracing. */
@@ -82,6 +82,12 @@ export const creationStart = (
const isRedraw = (tracing: Tracing | null) => tracing?.target === 'replace'
/** Backspace or « Retirer le dernier sommet »: the redraw's vertex, or the creation's. */
function popTrace({ tracing, dispatch }: PlacementInput): void {
if (isRedraw(tracing)) dispatch({ type: 'trace_pop' })
else popVertex()
}
/**
* Tracing with the zone and link tools: vertices, closing, Enter, Backspace and Escape. A
* redraw's tracing is the reducer's; a new shape's is the creation's (A12): its Escape
@@ -104,14 +110,12 @@ function tracingActions(input: PlacementInput) {
return dispatch({ type: 'trace_add', point: asPoint(at) })
traceVertex(creationStart(input, 'tool'), TOOL_TARGET[tool], asPoint(at))
}
const pop = () =>
isRedraw(tracing) ? dispatch({ type: 'trace_pop' }) : popVertex()
const onTraceKey = (event: KeyboardEvent) => {
if (!tracing) return
if (event.key === 'Enter') closeTracing()
if (event.key === 'Backspace') {
event.preventDefault()
pop()
popTrace(input)
}
if (event.key === 'Escape') {
event.preventDefault()
@@ -119,7 +123,7 @@ function tracingActions(input: PlacementInput) {
else askCreation()
}
}
return { closeTracing, trace, onTraceKey, pop }
return { closeTracing, trace, onTraceKey }
}
/**
@@ -202,6 +206,6 @@ export function usePlacement(input: PlacementInput) {
onDrop: dropAction(input),
onTraceKey: tracing.onTraceKey,
closeTracing: tracing.closeTracing,
popVertex: tracing.pop,
popVertex: () => popTrace(input),
}
}