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
@@ -746,6 +746,9 @@ Order (BDR-071): P0 docs + decisions → V1-1 clients and animals → V1-2 sheet
|
||||
- [x] V1-2.6 UX U2 design: boards 02-06, 13 redrawn + extras from 31 (owner brief 2026-11-17 « R4 est terminé … préparer U2 », orientation 2026-11-14 BDR-117; contract `.claude/tasks/contracts/2026-11-17-u2-design-boards.md`; docs only, no code, no DEV, no merge). [x] audit as built · [x] boards + REVUE + ARBITRAGES in `docs/design/v1-2-6-u2/` (bc19481, fixes 8bdb23a and pass 3) · [x] fresh design review (5 must-fix, 19 should, 19 observations; fixed) · [x] fresh conformity check (ECARTS(4), then re-check ECARTS(1) on 8bdb23a: two labels, fixed) · [x] owner validation 2026-11-17: nine boards + A1-A15 as recommended, adjustments A13 hint, A14 no shift, board 33 messages (ARBITRAGES « Validation du propriétaire »)
|
||||
- [x] V1-2.6 UX U2 technical plan (owner brief 2026-11-17 « conception graphique U2 validée … plan technique »): plan `.claude/tasks/plans/2026-11-17-v1-2-6-u2.md` · [x] audit · [x] plan rev 1 · [x] three fresh plan-challengers (rev 1: correctness FATAL(9), robustness FATAL(9), simplicity CONCERNS(5); rev 2 integrates them) · [x] owner approval 2026-11-17 (rev 2 + D1, D2 with zoom hint R-18, R-12 corrected) → rev 3, BDR-123
|
||||
- [ ] V1-2.6 UX U2 implementation (contract `.claude/tasks/contracts/2026-11-17-v1-2-6-u2-implementation.md`, plan rev 3, subagent-driven): [ ] T1 core min radius · [ ] T2 press machine · [ ] T3 strip + message, no shift · [ ] T4 points, move mode, guard · [ ] T5 zones, redraw, R-18 · [ ] T6 properties dialog · [ ] T7 creation · [ ] T8 touch, loupe · [ ] T9 docs · [ ] T10 gates, verifier, security · [ ] STOP owner trial on `pnpm db:trial` before closure
|
||||
- [ ] `shortcut:` the « − » bubble for a mouse is 28 × 22 px, read off board 05 (R-9 gives only the touch size), `apps/app/src/editor/annotations/handleSize.ts`. Upgrade: the owner's value at the trial (U2 Task 5).
|
||||
- [ ] No `scroll-padding-top` under the sticky top bar (pre-existing, WCAG 2.4.11): a keyboard focus on the header's « Défaire », « Refaire » or « Enregistrer » while scrolled can stay hidden under it; axe target-size flags them once a list click scrolled the page (U2 Task 5 review M-3).
|
||||
- [ ] At the page's end, a side panel that shortens (the issue list leaving it) clamps the scroll and moves the canvas by its height (11 px in `editor-geometry.spec.ts`, which starts from the top for that reason). Expected to go with Task 6 (properties in a dialog); recheck then (U2 Task 5 fix round 1).
|
||||
- [ ] Test anomaly A (owner 2026-11-09, separate from U1/U2): fictitious fingerprints `'a'.repeat(64)` from worker stand-ins (`packages/supabase/tests/sandbox/sheet-fixtures.ts:115` openRound, `sheets-concurrency.sandbox.ts:168`, `sheets-perf.sandbox.ts:169`); 7 published/deprecated sandbox versions fail `check_published`. Fix: real fingerprint through the core (as e2e `fingerprintOf`, `apps/app/e2e/support/catalogue.ts:88`); never weaken the publish gate or the reader check. Needs its own go. Census 2026-11-17 (R4 Task 3, read-only): 4 of 164 catalogue entries fail, the four current « Cheval sandbox » versions (2 at v1, 2 at v2), all `fingerprint_mismatch`; R4 cards show them with the integrity line.
|
||||
- [ ] Test anomaly B (owner 2026-11-09, separate from U1/U2): `packages/supabase/tests/sandbox/sheets-admin.sandbox.ts:181-195` creates the historical working copy and never archives it; slot taken → `admin.spec.ts:717` fails x4. Fix test independence and cleanup; the existing copy `8c315a12-20d4-4432-9db3-7cb88b27a5b4` stays untouched until the owner authorises. Linked: RR-13, the admin.spec confirmation line above.
|
||||
- [x] Test anomaly C (owner 2026-11-09, separate from U1/U2): CLOSED 2026-11-17 with R4's owner validation. Integrity failure invisible in catalogue cards; implemented as lot R4; failure shown, never hidden or bypassed. Built 2026-11-17 (R4 Task 1-3 and final fix wave, `V1-2-6_U1_CORRECTIONS.md` §5 row C: built by R4, closes on the owner's validation); checked off with R4's owner validation.
|
||||
|
||||
@@ -617,11 +617,6 @@ test.describe('deselect and D6b (touch, editor at 1 280 px)', () => {
|
||||
// c. Within 36 px of the canvas bottom, above the add buttons.
|
||||
await select(page, POINT)
|
||||
await takeRecord(page)
|
||||
// U2 Task 5: without the coordinate fields the properties panel is shorter than the
|
||||
// overview, so with the page scrolled to its end the deselect's swap (aside content,
|
||||
// until Task 6) grows the page and scrolls it before the tap's click lands. The tap
|
||||
// is made from the top of the page; the hazard is reported for Task 6.
|
||||
await page.evaluate(() => window.scrollTo(0, 0))
|
||||
await box(page).scrollIntoViewIfNeeded()
|
||||
const rect = (await box(page).boundingBox())!
|
||||
const bottom = { x: rect.x + rect.width / 2, y: rect.y + rect.height - 36 }
|
||||
@@ -630,6 +625,8 @@ test.describe('deselect and D6b (touch, editor at 1 280 px)', () => {
|
||||
await tap(cdp, bottom)
|
||||
await expectDeselected(page)
|
||||
await expect(creationPanel(page)).toHaveCount(0)
|
||||
// The page ends lower once the overview is back: the drawing stays where it was.
|
||||
expect((await box(page).boundingBox())!.y).toBe(rect.y)
|
||||
await report('c tap 36 px above the canvas bottom')
|
||||
|
||||
// d. About 6 px outside a marker: the marker or nothing, never both.
|
||||
|
||||
@@ -201,9 +201,9 @@ test.describe('editor geometry (adversarial)', () => {
|
||||
// A partial move (still out of the frame): refused by the core, the point restored.
|
||||
// Nothing around the drawing moves (A14); the side panel's content may (Task 6).
|
||||
const swaps = ['aside-content'] as const
|
||||
// The list row scrolled the page to its end. Without the coordinate fields (U2 Task 5)
|
||||
// the panel is short enough that the issue list leaving it (aside content, exempt until
|
||||
// Task 6) would clamp that scroll: the check starts from the top.
|
||||
// NOT a Playwright artefact: at the page's end, the issue list leaving the panel shortens
|
||||
// the page by 11 px and the scroll clamp moves the canvas (reported, U2 Task 5 fix round
|
||||
// 1; Task 6 moves the panel out of the page). The check starts from the top.
|
||||
await page.evaluate(() => window.scrollTo(0, 0))
|
||||
await expectNoShift(page, () => move.click(), swaps)
|
||||
await dragInMode(page, { x: 250, y: 250 }, { x: 260, y: 260 })
|
||||
|
||||
@@ -316,8 +316,7 @@ test.describe('editor journey (owner trial steps)', () => {
|
||||
await historyButton(page, dict, 'undo').click()
|
||||
await historyButton(page, dict, 'redo').click()
|
||||
const modified = await modifyAnnotations(page)
|
||||
// The last list row scrolled the page: the shell's top bar would cover « Enregistrer »
|
||||
// (axe target-size); the shorter panel of U2 Task 5 made that scroll reach it.
|
||||
// Playwright's auto-scroll to the last list row left « Enregistrer » under the top bar.
|
||||
await page.evaluate(() => window.scrollTo(0, 0))
|
||||
await expectAccessible(page, 'the editor with annotations')
|
||||
await saveDraft(page, dict, 1)
|
||||
|
||||
@@ -78,6 +78,22 @@ const button = (page: Page, key: string) =>
|
||||
page.getByRole('button', { name: dict[key], exact: true })
|
||||
const undo = (page: Page) => page.keyboard.press('Control+z')
|
||||
|
||||
/** An undo back to `points`, nothing around the drawing moving (A14). */
|
||||
async function undoTo(
|
||||
page: Page,
|
||||
points: () => Promise<unknown>,
|
||||
expected: unknown,
|
||||
) {
|
||||
await expectNoShift(
|
||||
page,
|
||||
async () => {
|
||||
await undo(page)
|
||||
await expect.poll(points).toEqual(expected)
|
||||
},
|
||||
SWAPS,
|
||||
)
|
||||
}
|
||||
|
||||
/** A press and release at the centre of a handle's hit shape. */
|
||||
async function pressHandle(page: Page, name: string) {
|
||||
const box = (await handle(page, name).locator('[data-handle]').boundingBox())!
|
||||
@@ -128,7 +144,7 @@ test.describe('editor zones on the drawing (U2 Task 5)', () => {
|
||||
await expect(page.getByTestId('edit-strip-notice')).toContainText(
|
||||
dict['editor.annotations.strip.zoom_hint'],
|
||||
)
|
||||
// The list row scrolled the page: the shell's top bar would cover the header's buttons.
|
||||
// Playwright's auto-scroll to the list row left the header under the sticky top bar.
|
||||
await page.evaluate(() => window.scrollTo(0, 0))
|
||||
await expectAccessible(page, 'a selected zone: vertices and « + »')
|
||||
const stored = await shownPoints(page)
|
||||
@@ -146,8 +162,7 @@ test.describe('editor zones on the drawing (U2 Task 5)', () => {
|
||||
)
|
||||
const [, moved] = await shownPoints(page)
|
||||
expect(Math.abs(moved[1] - 620)).toBeLessThan(3)
|
||||
await undo(page)
|
||||
await expect.poll(() => shownPoints(page)).toEqual(stored)
|
||||
await undoTo(page, () => shownPoints(page), stored)
|
||||
|
||||
// « + » on the segment from vertex 2: a vertex added and chosen, then undone.
|
||||
await expectNoShift(
|
||||
@@ -164,11 +179,19 @@ test.describe('editor zones on the drawing (U2 Task 5)', () => {
|
||||
await expect(page.getByTestId('edit-strip-detail')).toContainText(
|
||||
'sommet 3 choisi',
|
||||
)
|
||||
await undo(page)
|
||||
await expect.poll(() => count(page)).toBe(9)
|
||||
await undoTo(page, () => count(page), 9)
|
||||
|
||||
// « − » on the chosen vertex 3, then undone.
|
||||
await pressHandle(page, 'Sommet 3')
|
||||
await expectNoShift(
|
||||
page,
|
||||
async () => {
|
||||
await pressHandle(page, 'Sommet 3')
|
||||
await expect(page.getByTestId('edit-strip-detail')).toContainText(
|
||||
'sommet 3 choisi',
|
||||
)
|
||||
},
|
||||
SWAPS,
|
||||
)
|
||||
await expectNoShift(
|
||||
page,
|
||||
async () => {
|
||||
@@ -180,8 +203,7 @@ test.describe('editor zones on the drawing (U2 Task 5)', () => {
|
||||
SWAPS,
|
||||
)
|
||||
expect(await count(page)).toBe(8)
|
||||
await undo(page)
|
||||
await expect.poll(() => shownPoints(page)).toEqual(stored)
|
||||
await undoTo(page, () => shownPoints(page), stored)
|
||||
|
||||
// The interior dragged by the mouse moves the zone as a block, then undone.
|
||||
await expectNoShift(
|
||||
@@ -196,8 +218,31 @@ test.describe('editor zones on the drawing (U2 Task 5)', () => {
|
||||
)
|
||||
const [first] = await shownPoints(page)
|
||||
expect(Math.abs(first[0] - (stored[0][0] + 40))).toBeLessThan(3)
|
||||
await undo(page)
|
||||
await expect.poll(() => shownPoints(page)).toEqual(stored)
|
||||
await undoTo(page, () => shownPoints(page), stored)
|
||||
})
|
||||
|
||||
test('Thoraciques: « Désélectionner » commits the arrow steps pending on a vertex', async ({
|
||||
page,
|
||||
requests,
|
||||
}) => {
|
||||
const actor = await openThoracic(page)
|
||||
requests.forbid(actor.account.email, actor.account.password)
|
||||
await pickAnnotation(page, dict, THORACIC)
|
||||
const [, second] = await shownPoints(page)
|
||||
await handle(page, 'Sommet 2').focus()
|
||||
await page.keyboard.press('ArrowDown')
|
||||
// Not under expectNoShift: the button returns the focus to the list row, which
|
||||
// scrolls it into view by design.
|
||||
await page
|
||||
.getByTestId('annotation-properties')
|
||||
.getByRole('button', { name: dict['editor.annotations.deselect'] })
|
||||
.click()
|
||||
await expect(line(page)).toContainText(
|
||||
dict['editor.annotations.message.vertex_moved'],
|
||||
)
|
||||
await pickAnnotation(page, dict, THORACIC)
|
||||
const [, after] = await shownPoints(page)
|
||||
expect(after[1]).toBeGreaterThan(second[1])
|
||||
})
|
||||
|
||||
test('Thoraciques: redraw accepted, then refused, the old outline kept meanwhile', async ({
|
||||
@@ -235,17 +280,20 @@ test.describe('editor zones on the drawing (U2 Task 5)', () => {
|
||||
)
|
||||
await expect(selectionTag(page)).toContainText('Vertèbres thoraciques')
|
||||
expect(await count(page)).toBe(4)
|
||||
await undo(page)
|
||||
await expect.poll(() => shownPoints(page)).toEqual(stored)
|
||||
await undoTo(page, () => shownPoints(page), stored)
|
||||
|
||||
// Refused: a sliver; the tracing stays open with the core's message, then cancelled.
|
||||
await button(page, 'editor.annotations.redraw').click()
|
||||
await expectNoShift(
|
||||
page,
|
||||
() => button(page, 'editor.annotations.redraw').click(),
|
||||
SWAPS,
|
||||
)
|
||||
for (const [x, y] of [
|
||||
[900, 450],
|
||||
[1100, 452],
|
||||
[1300, 455],
|
||||
])
|
||||
await clickAt(page, x, y)
|
||||
await expectNoShift(page, () => clickAt(page, x, y), SWAPS)
|
||||
await expectNoShift(
|
||||
page,
|
||||
async () => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -16,6 +16,9 @@ import { answerDrawing, guardDrawing } from '@/editor/annotations/drawingGuard'
|
||||
import { useAnnotationWork, resetWork } from '@/editor/annotations/workStore'
|
||||
import { useUndoShortcuts } from '@/editor/useUndoShortcuts'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { fr } from '@/i18n/fr'
|
||||
import { stripLeadOf } from '@/editor/annotations/stripLead'
|
||||
import { initialUi } from '@/editor/annotations/uiState'
|
||||
import { drawnText, insert, point } from '../helpers/editorFixtures'
|
||||
import { openReady, pressAt, resetStore, store } from '../helpers/editorHarness'
|
||||
|
||||
@@ -139,6 +142,11 @@ const marker = (id: string) =>
|
||||
.getByTestId('annotation-canvas-drawing')
|
||||
.querySelector(`[data-anno-id="${id}"]`)!
|
||||
const detail = () => screen.getByTestId('edit-strip-detail')
|
||||
/** A « − » bubble still drawn, else the canvas box: what a press at its place reaches. */
|
||||
const liveBubbleOrCanvas = () =>
|
||||
screen
|
||||
.queryByRole('button', { name: /^Retirer le sommet/ })
|
||||
?.querySelector('[data-handle]') ?? screen.getByTestId('annotation-canvas')
|
||||
const message = () => screen.getByTestId('gesture-line')
|
||||
const chosen = () => useAnnotationWork.getState().chosen
|
||||
|
||||
@@ -208,9 +216,12 @@ describe('a vertex (R-9)', () => {
|
||||
expect(
|
||||
screen.queryByRole('button', { name: /^Retirer le sommet/ }),
|
||||
).toBeNull()
|
||||
void bubble
|
||||
const after = depth()
|
||||
pressAt(bubble, 50, 20)
|
||||
fireEvent.keyDown(vertex(2), { key: 'Delete' })
|
||||
// A press where the bubble was reaches what is there now: a bubble still shown, else the
|
||||
// box (which deselects).
|
||||
pressAt(liveBubbleOrCanvas(), 50, 20)
|
||||
expect(pointsOf('z')).toEqual(SQUARE)
|
||||
expect(depth()).toBe(after)
|
||||
})
|
||||
@@ -306,9 +317,9 @@ describe('a double click on a handle (R-8, carried Task 2 gap)', () => {
|
||||
await select()
|
||||
clickHandle('Sommet 2', [80, 20])
|
||||
const before = depth()
|
||||
const bubble = hitOf('Retirer le sommet 2')
|
||||
pressAt(bubble, 80, 10)
|
||||
pressAt(bubble, 80, 10)
|
||||
pressAt(hitOf('Retirer le sommet 2'), 80, 10)
|
||||
// The second click of the double click lands on what is there now, at the same place.
|
||||
pressAt(liveBubbleOrCanvas(), 80, 10)
|
||||
expect(pointsOf('z')).toHaveLength(4)
|
||||
expect(depth()).toBe(before + 1)
|
||||
})
|
||||
@@ -611,6 +622,159 @@ describe('redraw (R-12, board 06 C)', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('fix round 1: no lost series, no lost focus, no stale « − »', () => {
|
||||
it('I-1: ArrowRight then Insert, no Enter: the step is committed, then the insert', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
const before = depth()
|
||||
vertex(1).focus()
|
||||
fireEvent.keyDown(vertex(1), { key: 'ArrowRight' })
|
||||
fireEvent.keyDown(vertex(1), { key: 'Insert' })
|
||||
expect(pointsOf('z')).toEqual([[20.5, 20], [50.25, 20], ...SQUARE.slice(1)])
|
||||
expect(depth()).toBe(before + 2)
|
||||
})
|
||||
|
||||
it('I-1: ArrowDown then Delete, no Enter: the step is committed, then the removal', async () => {
|
||||
await mount(squareText([...SQUARE, [10, 50]]))
|
||||
await select()
|
||||
const before = depth()
|
||||
vertex(1).focus()
|
||||
fireEvent.keyDown(vertex(1), { key: 'ArrowDown' })
|
||||
fireEvent.keyDown(vertex(1), { key: 'Delete' })
|
||||
expect(pointsOf('z')).toEqual([...SQUARE.slice(1), [10, 50]])
|
||||
expect(depth()).toBe(before + 2)
|
||||
expect(message()).toHaveTextContent('Sommet retiré')
|
||||
})
|
||||
|
||||
it('I-2: « Désélectionner » commits a pending series on a vertex', async () => {
|
||||
await mount(squareText())
|
||||
const panel = await select()
|
||||
const before = depth()
|
||||
vertex(2).focus()
|
||||
fireEvent.keyDown(vertex(2), { key: 'ArrowDown' })
|
||||
fireEvent.click(
|
||||
within(panel).getByRole('button', { name: 'Désélectionner' }),
|
||||
)
|
||||
expect(pointsOf('z')![1]).toEqual([80, 20.5])
|
||||
expect(depth()).toBe(before + 1)
|
||||
expect(message()).toHaveTextContent('Sommet déplacé')
|
||||
})
|
||||
|
||||
it('I-2: « Désélectionner » commits a pending series on a point handle', async () => {
|
||||
await mount(insert(drawnText(), point('p', 50, 50, 5)))
|
||||
const panel = await select()
|
||||
const before = depth()
|
||||
const handle = screen.getByTestId('point-handle')
|
||||
handle.focus()
|
||||
fireEvent.keyDown(handle, { key: 'ArrowRight' })
|
||||
fireEvent.click(
|
||||
within(panel).getByRole('button', { name: 'Désélectionner' }),
|
||||
)
|
||||
expect(annotationOf('p').geometry).toMatchObject({ cx: 50.5 })
|
||||
expect(depth()).toBe(before + 1)
|
||||
})
|
||||
|
||||
it('M-1: Delete on the last vertex keeps the focus on a vertex', async () => {
|
||||
await mount(squareText([...SQUARE, [10, 50]]))
|
||||
await select()
|
||||
act(() => vertex(5).focus())
|
||||
fireEvent.keyDown(vertex(5), { key: 'Delete' })
|
||||
expect(pointsOf('z')).toHaveLength(4)
|
||||
expect(document.activeElement).toBe(vertex(4))
|
||||
})
|
||||
|
||||
it('M-1: Enter on « − » keeps the focus on a vertex', async () => {
|
||||
await mount(squareText([...SQUARE, [10, 50]]))
|
||||
await select()
|
||||
act(() => vertex(2).focus())
|
||||
act(() => minus(2).focus())
|
||||
fireEvent.keyDown(minus(2), { key: 'Enter' })
|
||||
expect(pointsOf('z')).toHaveLength(4)
|
||||
expect(document.activeElement).toBe(vertex(2))
|
||||
})
|
||||
|
||||
it('M-2: a chosen vertex stamped on another text removes nothing', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
clickHandle('Sommet 2', [80, 20])
|
||||
const before = depth()
|
||||
act(() =>
|
||||
useAnnotationWork.setState({
|
||||
chosen: { annotationId: 'z', vertex: 1, base: 'an older text' },
|
||||
}),
|
||||
)
|
||||
fireEvent.keyDown(vertex(2), { key: 'Delete' })
|
||||
pressAt(liveBubbleOrCanvas(), 80, 10)
|
||||
expect(pointsOf('z')).toEqual(SQUARE)
|
||||
expect(depth()).toBe(before)
|
||||
})
|
||||
})
|
||||
|
||||
describe('I-3: the click a touch tap synthesises is absorbed', () => {
|
||||
// A tap arms its absorber for 400 ms: let it lapse before the next test clicks.
|
||||
afterEach(() => new Promise((done) => setTimeout(done, 450)))
|
||||
const tapOn = (el: Element, pointerType: string) => {
|
||||
const init = {
|
||||
pointerId: 1,
|
||||
isPrimary: true,
|
||||
button: 0,
|
||||
buttons: 1,
|
||||
pointerType,
|
||||
clientX: 50,
|
||||
clientY: 50,
|
||||
}
|
||||
fireEvent.pointerDown(el, init)
|
||||
fireEvent.pointerUp(el, { ...init, buttons: 0 })
|
||||
}
|
||||
const addPoint = () =>
|
||||
screen.getByRole('button', { name: 'Ajouter un point' })
|
||||
/** A click at the tap's own place, as the browser synthesises it. */
|
||||
const clickAtTap = (el: Element) =>
|
||||
fireEvent.click(el, { clientX: 50, clientY: 50 })
|
||||
const creation = () => screen.queryByTestId('annotation-creation')
|
||||
|
||||
it('a touch tap: its click landing elsewhere does nothing; the next click does', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
tapOn(screen.getByTestId('annotation-canvas'), 'touch')
|
||||
expect(screen.queryByTestId('annotation-properties')).toBeNull()
|
||||
clickAtTap(addPoint())
|
||||
expect(creation()).toBeNull()
|
||||
clickAtTap(addPoint())
|
||||
expect(creation()).not.toBeNull()
|
||||
})
|
||||
|
||||
it('a pen tap is absorbed too; a mouse tap never is', async () => {
|
||||
await mount(squareText())
|
||||
tapOn(screen.getByTestId('annotation-canvas'), 'pen')
|
||||
clickAtTap(addPoint())
|
||||
expect(creation()).toBeNull()
|
||||
tapOn(screen.getByTestId('annotation-canvas'), 'mouse')
|
||||
clickAtTap(addPoint())
|
||||
expect(creation()).not.toBeNull()
|
||||
})
|
||||
|
||||
it('a click elsewhere right after a tap goes through', async () => {
|
||||
await mount(squareText())
|
||||
tapOn(screen.getByTestId('annotation-canvas'), 'touch')
|
||||
fireEvent.click(addPoint(), { clientX: 300, clientY: 300 })
|
||||
expect(creation()).not.toBeNull()
|
||||
})
|
||||
|
||||
it('a real click after the double-click window goes through', async () => {
|
||||
await mount(squareText())
|
||||
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
|
||||
try {
|
||||
tapOn(screen.getByTestId('annotation-canvas'), 'touch')
|
||||
act(() => void vi.advanceTimersByTime(450))
|
||||
clickAtTap(addPoint())
|
||||
expect(creation()).not.toBeNull()
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('the zoom hint for short segments (R-18, D2)', () => {
|
||||
const SHORT: Point[] = [
|
||||
[20, 20],
|
||||
@@ -674,3 +838,44 @@ describe('the zoom hint for short segments (R-18, D2)', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('M-5: « Fermeture refusée » titles a refused close only', () => {
|
||||
const t = (key: string) => (fr as Record<string, string>)[key] ?? key
|
||||
const tracing = (refused: boolean) => ({
|
||||
...initialUi,
|
||||
tool: 'zone' as const,
|
||||
hint: 'un autre message',
|
||||
tracing: {
|
||||
target: 'zone' as const,
|
||||
annotationId: null,
|
||||
points: [] as Point[],
|
||||
refused,
|
||||
},
|
||||
})
|
||||
|
||||
it('another hint during a tracing keeps the tracing title', () => {
|
||||
const lead = stripLeadOf(
|
||||
tracing(false),
|
||||
undefined,
|
||||
JSON.parse(drawnText()),
|
||||
{
|
||||
t,
|
||||
locale: 'fr',
|
||||
},
|
||||
)
|
||||
expect(lead.title).toBe('Ajouter une zone')
|
||||
})
|
||||
|
||||
it('a refused close says so', () => {
|
||||
const lead = stripLeadOf(
|
||||
tracing(true),
|
||||
undefined,
|
||||
JSON.parse(drawnText()),
|
||||
{
|
||||
t,
|
||||
locale: 'fr',
|
||||
},
|
||||
)
|
||||
expect(lead.title).toBe('Fermeture refusée')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user