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.
This commit is contained in:
1 parent
316d8c475c
commit
e596e0765e
17 files changed
+395
-57
No files matched your search
@@ -511,7 +511,8 @@ function SceneCommands({ scene, work }: { scene: Scene; work: Work }) {
|
||||
/**
|
||||
* The strip's middle, first match wins: a refusal (the strip's own, then a refused gesture
|
||||
* whose line under the drawing may be cut short: its full text here, A6), the selection's
|
||||
* geometry issues (the first, then « +n »), then why a tool cannot be used now.
|
||||
* geometry issues (the first, then « +n »), R-18's zoom line for a hidden « + », then why
|
||||
* a tool cannot be used now.
|
||||
*/
|
||||
function useStripNotice(
|
||||
scene: Scene,
|
||||
|
||||
@@ -243,19 +243,38 @@ function useChosen(annotationId: string, count: number): number | null {
|
||||
})
|
||||
}
|
||||
|
||||
/** Whether the focus is on this group, or fell to the page from it (its handle unmounted). */
|
||||
function focusIsOurs(group: SVGGElement, held: boolean): boolean {
|
||||
const active = document.activeElement
|
||||
if (group.contains(active)) return true
|
||||
const fell =
|
||||
active === null || active === document.body || !active.isConnected
|
||||
return held && fell
|
||||
}
|
||||
|
||||
/**
|
||||
* A keyboard choice (« + », Insert, Delete) moves the focus to the vertex now chosen, so
|
||||
* the keys keep acting where the user looks; a pointer choice leaves the focus alone.
|
||||
* A keyboard choice (« + », Insert, Delete, Enter on « − ») moves the focus to the vertex
|
||||
* now chosen, so the keys keep acting where the user looks, even when the focused handle
|
||||
* was removed; a pointer choice leaves the focus alone. It follows every new choice (the
|
||||
* store's object), a re-choice of the same index on a new text included.
|
||||
*/
|
||||
function useFocusFollowsChoice(chosen: number | null) {
|
||||
const group = useRef<SVGGElement | null>(null)
|
||||
const held = useRef(false)
|
||||
const choice = useAnnotationWork((s) => s.chosen)
|
||||
useLayoutEffect(() => {
|
||||
const element = group.current
|
||||
if (chosen === null || !element || !focusIsOurs(element, held.current))
|
||||
return
|
||||
const active = document.activeElement
|
||||
if (chosen === null || !group.current?.contains(active)) return
|
||||
if (active?.getAttribute('data-vertex') === String(chosen)) return
|
||||
const target = group.current.querySelector(`[data-vertex="${chosen}"]`)
|
||||
const target = element.querySelector(`[data-vertex="${chosen}"]`)
|
||||
if (target instanceof SVGElement) target.focus()
|
||||
}, [chosen])
|
||||
}, [chosen, choice])
|
||||
// Read after every commit: where the focus was before the next change unmounts it.
|
||||
useLayoutEffect(() => {
|
||||
held.current = group.current?.contains(document.activeElement) ?? false
|
||||
})
|
||||
return group
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from '@/editor/focusRequest'
|
||||
import { CANVAS_BOX } from '@/editor/useEditorNavigation'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { commitFocusedSeries } from './drawingGuard'
|
||||
import { escapeAction, type EscapeAction } from './escape'
|
||||
import { endMode, useAnnotationWork } from './workStore'
|
||||
|
||||
@@ -50,6 +51,9 @@ export function useDeselect(id: string | null, clear: () => void) {
|
||||
const run = (focus: ((id: string) => unknown) | null) => {
|
||||
if (id === null) return false
|
||||
commitFocusedField()
|
||||
// A handle's arrow series commits on its blur; removing the handle fires none under
|
||||
// the HTML focus fix-up (Firefox), so it is committed before (BDR-050).
|
||||
commitFocusedSeries()
|
||||
flushSync(clear)
|
||||
focus?.(id)
|
||||
announce(tRef.current('editor.annotations.deselected'))
|
||||
|
||||
@@ -4,7 +4,7 @@ import { endMode, guardWork, useAnnotationWork } from './workStore'
|
||||
* A keyboard series or a size change still pending (no blur yet: a mouse Back button)
|
||||
* commits now, through its own blur (BDR-050): leaving never drops it.
|
||||
*/
|
||||
function commitFocusedSeries(): void {
|
||||
export function commitFocusedSeries(): void {
|
||||
const { preview } = useAnnotationWork.getState()
|
||||
if (!preview || preview.source === 'move') return
|
||||
const active = document.activeElement
|
||||
|
||||
@@ -169,7 +169,10 @@ export function stripLeadOf(
|
||||
(a) => a.id === ui.tracing?.annotationId,
|
||||
)
|
||||
const name = replaced ? annotationName(replaced, doc.views, ctx.locale) : ''
|
||||
return tracingLead(ui.tracing, name, { ...ctx, refused: ui.hint !== null })
|
||||
return tracingLead(ui.tracing, name, {
|
||||
...ctx,
|
||||
refused: ui.tracing.refused,
|
||||
})
|
||||
}
|
||||
if (selected) return selectionLead(selected, doc.views, ctx)
|
||||
const lead = TOOL_LEAD[ui.tool]
|
||||
|
||||
@@ -9,6 +9,8 @@ export interface Tracing {
|
||||
/** The annotation whose geometry the tracing replaces (target `replace`). */
|
||||
annotationId: string | null
|
||||
points: Point[]
|
||||
/** The core refused its close (board 33 A): the strip says « Fermeture refusée ». */
|
||||
refused: boolean
|
||||
}
|
||||
|
||||
export interface UiState {
|
||||
@@ -37,6 +39,7 @@ export type UiAction =
|
||||
| { type: 'trace_add'; point: Point }
|
||||
| { type: 'trace_pop' }
|
||||
| { type: 'trace_cancel' }
|
||||
| { type: 'trace_refused'; hint: string }
|
||||
| { type: 'hint'; hint: string | null }
|
||||
| { type: 'filter'; term: string }
|
||||
| { type: 'size'; size: number | null }
|
||||
@@ -64,6 +67,16 @@ const TOOL_OF: Record<Tracing['target'], ToolId> = {
|
||||
const toolAfterTracing = (state: UiState): ToolId =>
|
||||
state.tracing?.target === 'replace' ? 'select' : state.tool
|
||||
|
||||
/** The tracing with new points: a refusal of its close no longer applies, nor its message. */
|
||||
function retraced(state: UiState, points: Point[]): UiState {
|
||||
const tracing = state.tracing!
|
||||
return {
|
||||
...state,
|
||||
hint: tracing.refused ? null : state.hint,
|
||||
tracing: { ...tracing, points, refused: false },
|
||||
}
|
||||
}
|
||||
|
||||
export function uiReducer(state: UiState, action: UiAction): UiState {
|
||||
switch (action.type) {
|
||||
case 'view':
|
||||
@@ -106,26 +119,23 @@ export function uiReducer(state: UiState, action: UiAction): UiState {
|
||||
target: action.target,
|
||||
annotationId: action.annotationId ?? null,
|
||||
points: [],
|
||||
refused: false,
|
||||
},
|
||||
}
|
||||
case 'trace_add':
|
||||
return state.tracing
|
||||
? {
|
||||
...state,
|
||||
tracing: {
|
||||
...state.tracing,
|
||||
points: [...state.tracing.points, action.point],
|
||||
},
|
||||
}
|
||||
? retraced(state, [...state.tracing.points, action.point])
|
||||
: state
|
||||
case 'trace_pop':
|
||||
return state.tracing
|
||||
? retraced(state, state.tracing.points.slice(0, -1))
|
||||
: state
|
||||
case 'trace_refused':
|
||||
return state.tracing
|
||||
? {
|
||||
...state,
|
||||
tracing: {
|
||||
...state.tracing,
|
||||
points: state.tracing.points.slice(0, -1),
|
||||
},
|
||||
hint: action.hint,
|
||||
tracing: { ...state.tracing, refused: true },
|
||||
}
|
||||
: state
|
||||
case 'trace_cancel':
|
||||
|
||||
@@ -55,7 +55,7 @@ function closeRedraw(input: PlacementInput, tracing: Tracing): void {
|
||||
const result = updateGeometry(annotation, polygon, context)
|
||||
if (!result.ok) {
|
||||
useAnnotationWork.setState({ mode: held })
|
||||
return dispatch({ type: 'hint', hint: result.messages.join(' ') })
|
||||
return dispatch({ type: 'trace_refused', hint: result.messages.join(' ') })
|
||||
}
|
||||
dispatch({ type: 'select', id: annotation.id })
|
||||
const text = context.t(
|
||||
|
||||
@@ -4,6 +4,8 @@ import { clientToDrawing, drawingPerClientPx } from './gesture'
|
||||
import { HANDLE_CAP } from './polygonEdit'
|
||||
import {
|
||||
CLOSE_PX,
|
||||
DOUBLE_MS,
|
||||
DOUBLE_PX,
|
||||
clickAction,
|
||||
dragAction,
|
||||
isDoubleClick,
|
||||
@@ -152,8 +154,35 @@ function selectClick(f: Feed, target: PressTarget, event: PointerEvent): void {
|
||||
runClick(double ? doubled(action, target, sel) : action, f.input)
|
||||
}
|
||||
|
||||
/**
|
||||
* A touch or pen tap is decided at its pointer-up; the click the browser synthesises next,
|
||||
* at the tap's place, is hit-tested on the layout that decision produced and could land
|
||||
* on another control (« Ajouter un accès » under a page that grew). That one click is
|
||||
* absorbed, within the double-click window and its distance; a mouse click, a click
|
||||
* elsewhere and any later click go through.
|
||||
*/
|
||||
function absorbSynthesisedClick(at: XY): void {
|
||||
const stop = () => {
|
||||
clearTimeout(timer)
|
||||
document.removeEventListener('click', swallow, true)
|
||||
}
|
||||
const swallow = (event: MouseEvent) => {
|
||||
const near = Math.hypot(event.clientX - at.x, event.clientY - at.y)
|
||||
if (near > DOUBLE_PX) return
|
||||
event.preventDefault()
|
||||
// One tap absorbs one click: another armed listener waits for its own.
|
||||
event.stopImmediatePropagation()
|
||||
stop()
|
||||
}
|
||||
const timer = setTimeout(stop, DOUBLE_MS)
|
||||
document.addEventListener('click', swallow, true)
|
||||
}
|
||||
|
||||
/** A click with the select tool (none during the move mode, R-12), or with a drawing tool. */
|
||||
function onClick(f: Feed, target: PressTarget, event: PointerEvent): void {
|
||||
if (pointerKindOf(event.pointerType) !== 'mouse') {
|
||||
absorbSynthesisedClick(clientOf(event))
|
||||
}
|
||||
if (f.input.tool !== 'select') return place(f.input, event)
|
||||
if (!inMoveMode()) selectClick(f, target, event)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { stepSelection, takePreview } from './previewCommit'
|
||||
import type { Drop } from './usePlacement'
|
||||
import type { GestureMessages } from './useGestureMessage'
|
||||
import type { HandleAction } from './usePressGesture'
|
||||
import { chooseVertex, freshChosen } from './zoneEdit'
|
||||
import { chooseVertex, currentPoints, freshChosen } from './zoneEdit'
|
||||
import { useAnnotationWork } from './workStore'
|
||||
|
||||
export interface ZoneEditInput {
|
||||
@@ -27,8 +27,9 @@ const STEP: Record<string, [number, number]> = {
|
||||
ArrowRight: [1, 0],
|
||||
}
|
||||
|
||||
/** The selected polygon as stored now (not as this render saw it). */
|
||||
const pointsOf = (target: Annotation | null): Point[] | null =>
|
||||
target?.geometry?.type === 'polygon' ? target.geometry.points : null
|
||||
target ? currentPoints(target.id) : null
|
||||
|
||||
/** « + »: the midpoint commits once, and the new vertex is chosen on the new text. */
|
||||
function insertAfter(input: ZoneEditInput, after: number): void {
|
||||
@@ -61,9 +62,8 @@ function commitKeys(input: ZoneEditInput): void {
|
||||
const { target, onDrop } = input
|
||||
const preview = takePreview('keys')
|
||||
if (!target || !preview || preview.annotationId !== target.id) return
|
||||
const same =
|
||||
JSON.stringify(preview.geometry) === JSON.stringify(target.geometry)
|
||||
if (same) return
|
||||
const stored = { type: 'polygon', points: pointsOf(target) }
|
||||
if (JSON.stringify(preview.geometry) === JSON.stringify(stored)) return
|
||||
const vertex = freshChosen(target.id)
|
||||
const kept = onDrop(target.id, preview.geometry, 'vertex')
|
||||
if (kept && vertex !== null) chooseVertex(target.id, vertex)
|
||||
@@ -79,13 +79,16 @@ function stepVertex(input: ZoneEditInput, index: number, event: KeyboardEvent) {
|
||||
|
||||
const inMoveMode = () => useAnnotationWork.getState().mode?.kind === 'move'
|
||||
|
||||
/** Delete removes the chosen vertex; the next one is chosen so the focus stays on a vertex. */
|
||||
/**
|
||||
* Delete (or Enter on « − ») removes the chosen vertex; the next one is chosen so the focus
|
||||
* stays on a vertex (ZoneHandles follows the choice).
|
||||
*/
|
||||
function deleteChosen(input: ZoneEditInput): void {
|
||||
const id = input.target?.id
|
||||
const chosen = id ? freshChosen(id) : null
|
||||
if (id === undefined || chosen === null || !removeChosen(input, chosen))
|
||||
return
|
||||
const left = pointsOf(input.target)!.length - 2
|
||||
const left = pointsOf(input.target)!.length - 1
|
||||
chooseVertex(id, Math.min(chosen, left))
|
||||
}
|
||||
|
||||
@@ -100,6 +103,9 @@ function vertexKey(input: ZoneEditInput, index: number, event: KeyboardEvent) {
|
||||
event.preventDefault()
|
||||
return inMoveMode() ? input.confirmMove() : commitKeys(input)
|
||||
}
|
||||
if (event.key !== 'Insert' && event.key !== 'Delete') return
|
||||
// I-1: arrow steps still pending are committed first; the change applies to that place.
|
||||
commitKeys(input)
|
||||
const chosen = id ? freshChosen(id) : null
|
||||
if (event.key === 'Insert' && chosen !== null) insertAfter(input, chosen)
|
||||
if (event.key === 'Delete') deleteChosen(input)
|
||||
@@ -138,10 +144,11 @@ export function useZoneEdit(input: ZoneEditInput) {
|
||||
event.preventDefault()
|
||||
insertAfter(input, after)
|
||||
},
|
||||
onRemoveKey: (index: number, event: KeyboardEvent) => {
|
||||
// The bubble's own index is the chosen vertex (it is drawn only over that one).
|
||||
onRemoveKey: (_index: number, event: KeyboardEvent) => {
|
||||
if (!isPress(event)) return
|
||||
event.preventDefault()
|
||||
removeChosen(input, index)
|
||||
deleteChosen(input)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,3 +22,13 @@ export function freshChosen(annotationId: string): number | 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
|
||||
}
|
||||
@@ -6,6 +6,9 @@ html, body, #root { height: 100%; }
|
||||
html:has(dialog:modal) { overflow: hidden; }
|
||||
/* The editor keeps its scrollbar width whatever opens or closes (R-2, A14): nothing moves. */
|
||||
html:has([data-editor-workspace]) { scrollbar-gutter: stable; }
|
||||
/* Nor does the browser's scroll anchoring move it: a side panel growing under a tap at the
|
||||
page's end scrolled the drawing under the finger (U2 Task 5 fix round, A14). */
|
||||
body:has([data-editor-workspace]) { overflow-anchor: none; }
|
||||
body {
|
||||
background: var(--color-bg);
|
||||
color: var(--color-ink);
|
||||
|
||||
Reference in new issue
Block a user