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

@@ -56,8 +56,7 @@ const NONE: Outcome = { missing: [], messages: [] }
* undo); a point lets the core's verdict offer C (C26); a success ends the creation.
*/
function useCreate(work: Creation, created: { current: boolean }) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const context = { t: useT(), locale: useLocaleStore((s) => s.locale) }
const [outcome, setOutcome] = useState<Outcome>(NONE)
const settle = (attempt: Attempt) => {
if (attempt.status === 'invalid') {
@@ -74,44 +73,43 @@ function useCreate(work: Creation, created: { current: boolean }) {
if (attempt.id) finishCreation(attempt.id, work.pending.kind)
else dropCreation()
}
const input = { ...work, context: { t, locale } }
return {
outcome,
create: () => settle(createAttempt(input, work.form)),
create: () => settle(createAttempt({ ...work, context }, work.form)),
confirm: () => {
const { correction } = work.pending
if (correction) settle(confirmAttempt(input, work.form, correction))
if (!correction) return
settle(confirmAttempt({ ...work, context }, work.form, correction))
},
}
}
/** « Point placé · Replacer le point », « Zone tracée, 5 sommets · Reprendre le tracé ». */
function ShapeLine({ work, readOnly }: { work: Creation; readOnly: boolean }) {
const GLYPH = { point: 'point', zone: 'zone', detail_trigger: 'link' } as const
/** « Point placé », « Zone tracée, 5 sommets », « Accès tracé, 3 sommets ». */
function useShapeText(pending: Creation['pending']): string {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const { kind, geometry } = work.pending
const count = geometry.type === 'polygon' ? geometry.points.length : 0
const text =
kind === 'point'
? t('editor.annotations.creation.placed')
: t(
pluralKey(
locale,
`editor.annotations.creation.traced.${kind}`,
count,
),
).replace('{count}', String(count))
const point = kind === 'point'
const { kind, geometry } = pending
if (geometry.type !== 'polygon')
return t('editor.annotations.creation.placed')
const count = geometry.points.length
const key = `editor.annotations.creation.traced.${kind}`
return t(pluralKey(locale, key, count)).replace('{count}', String(count))
}
function ShapeLine({ work, readOnly }: { work: Creation; readOnly: boolean }) {
const t = useT()
const text = useShapeText(work.pending)
const point = work.pending.kind === 'point'
return (
<div
data-creation-focus=""
tabIndex={-1}
className="flex flex-wrap items-center gap-x-2 gap-y-1 rounded-lg bg-[var(--color-surface-strong)] px-3 py-2 text-sm outline-none"
>
<EditorGlyph
name={point ? 'point' : kind === 'zone' ? 'zone' : 'link'}
size={16}
/>
<EditorGlyph name={GLYPH[work.pending.kind]} size={16} />
<span>{text}</span>
<button
type="button"
@@ -257,14 +255,12 @@ export default function CreationDialog(props: CreationDialogProps) {
const visible = usePlaceVisible()
const work = useAnnotationWork((s) => s.creation)
const back = useCreationReturn(work)
const shown = visible && work !== null && work.dialog
const title = work ? t(`editor.annotations.new.${work.pending.kind}`) : ''
return (
<Dialog
open={shown}
open={visible && work !== null && work.dialog}
anchor={props.anchor}
veilCloses={false}
title={title}
title={work ? t(`editor.annotations.new.${work.pending.kind}`) : ''}
returnFocus={back.returnFocus}
onClose={() => (askDiscard() ? undefined : 'kept')}
>