fix(editor): no silent move loss, no empty commit, focus kept

- « Toutes les annotations » in the properties panel asks the drawing
  guard before it drops a started move (R-12); tests also cover a tool
  and « Ajouter un point ».
- A keyboard series back on its place, or a slider pinned at its stop,
  commits nothing.
- Escape that deselects from the handle or the slider moves the focus to
  the row (or the drawing) instead of losing it.
- A link circle keeps its handle, named « Accès {nom} », with no slider
  and no move mode (no label for it in REVUE).
- The move-mode drop notice waits until the body is shown (R-14).
- No layout shift: the strip's lead has a fixed width, the commands and
  the message pill get a new box per set or message.
- Doc: hit shapes use pointer-events auto; the fine « − » bubble is
  board 05's size.
- Tests: R-14 flip, A5 through the Point tool click, the repair e2e
  wrapped in expectNoShift.
This commit is contained in:
bchanot committed 2026-11-17 19:08:08 +01:00
1 parent 91e94952f0
commit 44de465c6d
10 files changed
+240 -35

No files matched your search

+11 -4
View File
@@ -24,6 +24,12 @@ export function focusRowOrDrawing(id: string): boolean {
return focusRow({ kind: 'annotation', id }) || focusDrawing()
}
/** The focused element left with the selection (a handle, the slider): the row takes it. */
function focusIfLost(id: string): void {
const active = document.activeElement
if (active === null || active === document.body) focusRowOrDrawing(id)
}
/** After a tap on the drawing: the box takes the focus, unless it already holds it. */
function drawingFocus(): void {
if (visibleElement(CANVAS_BOX) !== document.activeElement) focusDrawing()
@@ -31,9 +37,9 @@ function drawingFocus(): void {
/**
* Deselecting: `id` is the RESOLVED selection (never the raw id, which can name a removed
* annotation). The button always moves the focus to the row; Escape does only when it was
* pressed inside the properties panel, whose focused element is about to leave the page.
* Anywhere else the focus stays where it is. Both answer whether something was deselected.
* annotation). The button always moves the focus to the row; Escape does when it was
* pressed inside the properties panel, or when the focused element left with the selection
* (the handle, the slider, « Déplacer le point »). Anywhere else the focus stays where it is. Both answer whether something was deselected.
*/
export function useDeselect(id: string | null, clear: () => void) {
const t = useT()
@@ -50,7 +56,8 @@ export function useDeselect(id: string | null, clear: () => void) {
}
return {
byButton: () => run(focusRowOrDrawing),
byKey: (fromPanel: boolean) => run(fromPanel ? focusRowOrDrawing : null),
byKey: (fromPanel: boolean) =>
run(fromPanel ? focusRowOrDrawing : focusIfLost),
byDrawing: () => run(drawingFocus),
}
}
@@ -4,7 +4,12 @@ import { useEditorStore } from '../state/editorStore'
import { moveStep, type Frame } from './frame'
import type { GeometryChange } from './usePlacement'
import { takeMove, takePreview, stepSelection } from './previewCommit'
import { endMode, startMove, useAnnotationWork } from './workStore'
import {
endMode,
startMove,
useAnnotationWork,
type Preview,
} from './workStore'
type Drop = (id: string, geometry: Geometry, change?: GeometryChange) => void
@@ -40,15 +45,26 @@ function step(input: PointEditInput, direction: Direction, big: boolean) {
stepSelection(target.id, target.geometry, { x: x * size, y: y * size })
}
/** The commits of the pending work: each takes its preview, fresh only (R-13). */
function commits(onDrop: Drop) {
/** A preview back on the stored shape (there and back, a pinned slider) is no change. */
function changed(
preview: Preview | null,
target: Annotation | null,
): preview is Preview {
if (!preview || preview.annotationId !== target?.id) return false
return JSON.stringify(preview.geometry) !== JSON.stringify(target.geometry)
}
/** The commits of the pending work: each takes its preview, fresh and changed only (R-13). */
function commits({ onDrop, target }: PointEditInput) {
const keys = () => {
const preview = takePreview('keys')
if (preview) onDrop(preview.annotationId, preview.geometry)
if (changed(preview, target)) onDrop(preview.annotationId, preview.geometry)
}
const size = () => {
const preview = takePreview('size')
if (preview) onDrop(preview.annotationId, preview.geometry, 'size')
if (changed(preview, target)) {
onDrop(preview.annotationId, preview.geometry, 'size')
}
}
const move = () => {
const preview = takeMove()
@@ -80,7 +96,7 @@ function handleKeys(input: PointEditInput, commit: ReturnType<typeof commits>) {
* « Valider la position » committing once, « Annuler »).
*/
export function usePointEdit(input: PointEditInput) {
const commit = commits(input.onDrop)
const commit = commits(input)
return {
onHandleKey: handleKeys(input, commit),
// BDR-050: leaving the handle commits its series; a move mode waits for « Valider ».