fix(editor): the drawing stays clear of the strip while the page scrolls

The drawing column (chips, tools, canvas, add row, message line) is
pinned under the strip from 1 024 px wide and 644 px high; the canvas
box is capped in width by the window height (4:3 kept, unchanged at the
three sizes); pinned controls carry no strip margin. The rev 4 test
workarounds go; the row-click scroll was Playwright's bring-into-view.
This commit is contained in:
bchanot committed 2026-11-19 20:19:26 +01:00
1 parent da04c79d13
commit 36ed9f980b
7 files changed
+286 -31

No files matched your search

@@ -20,7 +20,6 @@ import {
reloadAccepting,
revisionText,
saveLine,
scrollToTop,
seedDraft,
selectionTag,
selectTab,
@@ -141,18 +140,6 @@ async function expectDeselected(page: Page) {
await expect(overview(page)).toBeVisible()
}
/** The client point hits the canvas box, not the sticky strip or bar over it. */
async function expectOnDrawing(page: Page, at: { x: number; y: number }) {
const hit = await page.evaluate(
({ x, y }) =>
document
.elementFromPoint(x, y)
?.closest('[data-testid="annotation-canvas"]') != null,
at,
)
expect(hit, `${at.x}, ${at.y} lands on the drawing`).toBe(true)
}
/** A negative check: the state is still there after two animation frames. */
async function expectKept(page: Page, name: string) {
await frames(page)
@@ -305,9 +292,6 @@ test.describe('deselect and D6b (editor, mouse and keyboard)', () => {
requests.forbid(actor.account.email, actor.account.password)
await select(page, POINT)
for (const at of [IN_CIRCLE, IN_RECT, IN_ROOT]) {
// The row click scrolled the page: the drawing's top band is under the sticky strip.
await scrollToTop(page)
await expectOnDrawing(page, await clientOf(page, at.x, at.y))
await clickAt(page, at)
await expectDeselected(page)
await select(page, POINT)
@@ -640,11 +624,9 @@ test.describe('deselect and D6b (touch, editor at 1 280 px)', () => {
// b. Empty drawing, a zone about 40 px below the tap.
await select(page, POINT)
await scrollToTop(page)
await takeRecord(page)
const top = await clientOf(page, 175, 100)
const above = { x: top.x, y: top.y - 40 }
await expectOnDrawing(page, above)
expect(await annotationUnder(page, above)).toBeNull()
await tap(cdp, above)
await expectDeselected(page)
+219 -8
View File
@@ -606,6 +606,36 @@ function stripGeometry(page: Page) {
})
}
/**
* The pinned drawing column (U2 Task 17): its box, the canvas box, what is painted at the
* canvas's top centre, and whether the page scrolls sideways.
*/
function columnGeometry(page: Page) {
return page.evaluate(() => {
const column = document.querySelector('[data-drawing-column]')!
const canvas = document.querySelector('[data-testid="annotation-canvas"]')!
const box = column.getBoundingClientRect()
const drawing = canvas.getBoundingClientRect()
const frame = document
.querySelector('[data-canvas-box]')!
.getBoundingClientRect()
const hit = document.elementFromPoint(
drawing.x + drawing.width / 2,
drawing.y + 2,
)
const root = document.documentElement
return {
top: box.top,
bottom: box.bottom,
canvas: { y: drawing.y, width: drawing.width, height: drawing.height },
canvasTopPainted: !!hit && canvas.contains(hit),
// Not capped: the canvas box still runs to the column's right edge.
canvasFills: Math.abs(frame.right - box.right) < 0.5,
sideways: root.scrollWidth > root.clientWidth,
}
})
}
/**
* The focused element's top against the bottom of what covers it (the strip in the drawing
* place, else the bar); null on the sticky chrome itself, whose focus never scrolls the page.
@@ -640,6 +670,13 @@ function focusedUnderStrip(page: Page) {
})
}
/**
* A window too short for the pinned drawing column (U2 Task 17: pinned from 40.25 rem high):
* the drawing scrolls under the strip as before, and the strip's margin brings a focus out.
*/
const belowPinnedHeight = (page: Page) =>
page.setViewportSize({ width: page.viewportSize()!.width, height: 600 })
// Criterion 25: the header's « Enregistrer » and the tab row's « Défaire » and « Refaire » sit
// outside the drawing place; a keyboard focus on them, the page scrolled, never lands under the bar.
const HEADER_WIDTHS = [820, 1024, 1280]
@@ -766,9 +803,9 @@ for (const viewport of VIEWPORTS) {
window.scrollY,
selector,
)
const canvasTop = await flowTop('[data-testid="annotation-canvas"]')
const asideTop = await flowTop('[data-annotation-aside="edit"]')
const start = await stripGeometry(page)
const { canvas } = await columnGeometry(page)
expect(start.limit, 'the page must scroll').toBeGreaterThan(300)
for (let y = 0; y <= start.limit + 150; y += 150) {
@@ -783,9 +820,30 @@ for (const viewport of VIEWPORTS) {
now.innerHeight,
)
expect(now.covered, `strip painted at ${at}`).toBe(false)
// Task 17: the drawing column (chips to message line) is never under the strip
// and fits the window; the canvas keeps its size; nothing scrolls sideways.
const pinned = await columnGeometry(page)
expect(
pinned.top,
`column top below the strip at ${at}`,
).toBeGreaterThanOrEqual(now.bottom - 0.5)
// Stuck with the strip, all of it is in view (before, the page top shows its top).
if (now.top <= now.barBottom + 0.5)
expect(
pinned.bottom,
`column bottom in view at ${at}`,
).toBeLessThanOrEqual(now.innerHeight + 0.5)
expect(pinned.canvasTopPainted, `canvas top painted at ${at}`).toBe(
true,
)
expect(pinned.canvas.width, `canvas width at ${at}`).toBe(canvas.width)
expect(pinned.canvas.height, `canvas height at ${at}`).toBe(
canvas.height,
)
expect(pinned.sideways, `no sideways scroll at ${at}`).toBe(false)
expect(pinned.canvasFills, `canvas not capped at ${at}`).toBe(true)
}
// Sticky leaves the flow alone: the canvas and the aside keep their place.
expect(await flowTop('[data-testid="annotation-canvas"]')).toBe(canvasTop)
// Sticky leaves the flow alone: the aside keeps its place.
expect(await flowTop('[data-annotation-aside="edit"]')).toBe(asideTop)
const bottom = (await stripGeometry(page)).scrollY
@@ -820,8 +878,15 @@ for (const viewport of VIEWPORTS) {
test('a focus never scrolls onto the bar or the strip, nor lands under them', async ({
page,
}) => {
await open(page, ...manyPoints())
await pickAnnotation(page, dict, 'Pt 0')
// A marker large enough on the phone preview for its moves to be accepted.
const big = pointOf(
'pt-big',
'main',
{ cx: 500, cy: 400, r: 40 },
'Pt Big',
)
await open(page, ...manyPoints(), big)
await pickAnnotation(page, dict, 'Pt Big')
await page.evaluate(() => window.scrollTo(0, 300))
const before = (await stripGeometry(page)).scrollY
// The keyboard's focus move on the strip's command and on the bar's first control.
@@ -837,6 +902,36 @@ for (const viewport of VIEWPORTS) {
'focus on sticky chrome',
).toBe(before)
}
// U2 Task 17: nor on the pinned column's controls (the line's « Défaire », a view
// chip, the handle, an add button, the canvas box), each below the strip. A commit
// puts « Défaire » in the message line for 6 s.
await page.getByTestId('point-handle').focus()
await page.keyboard.press('ArrowRight')
await page.keyboard.press('Enter')
const line = page.getByTestId('gesture-line')
const undo = line.getByRole('button', {
name: dict['editor.history.undo_title'],
})
await expect(undo).toBeVisible()
for (const target of [
undo,
viewChip(page, 'Vue principale'),
page.getByTestId('point-handle'),
page.locator('[data-add-kind="point"]'),
page.getByTestId('annotation-canvas'),
]) {
await target.focus()
const label = await target.evaluate(
(el) => el.getAttribute('aria-label') ?? el.textContent,
)
expect((await stripGeometry(page)).scrollY, `focus on ${label}`).toBe(
before,
)
expect(
(await target.boundingBox())!.y,
`${label} below the strip`,
).toBeGreaterThanOrEqual((await stripGeometry(page)).bottom - 0.5)
}
// A row hidden under the strip comes out below it, not under it. The row sits low in the
// page: a short window lets the page scroll far enough to put it under the strip.
await page.setViewportSize({
@@ -864,9 +959,10 @@ for (const viewport of VIEWPORTS) {
)
})
test('a vertex handle (SVG) focused under the strip ends below it', async ({
test('a vertex handle (SVG) focused under the strip ends below it (window below the pinned height)', async ({
page,
}) => {
await belowPinnedHeight(page)
await open(page, ...manyPoints(), {
...pointOf('zone-v', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone V'),
kind: 'zone',
@@ -901,9 +997,10 @@ for (const viewport of VIEWPORTS) {
).toBeGreaterThanOrEqual((await stripGeometry(page)).bottom)
})
test("Tab and Shift+Tab onto the drawing place's native controls land below the strip", async ({
test("Tab and Shift+Tab onto the drawing place's native controls land below the strip (window below the pinned height)", async ({
page,
}) => {
await belowPinnedHeight(page)
await open(page, ...manyPoints())
await pickAnnotation(page, dict, 'Pt 0')
// A commit puts « Défaire » in the message line under the drawing.
@@ -934,9 +1031,10 @@ for (const viewport of VIEWPORTS) {
}
})
test('Delete from the keyboard focuses the next vertex below the strip', async ({
test('Delete from the keyboard focuses the next vertex below the strip (window below the pinned height)', async ({
page,
}) => {
await belowPinnedHeight(page)
await open(page, ...manyPoints(), {
...pointOf('zone-k', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone K'),
kind: 'zone',
@@ -975,6 +1073,73 @@ for (const viewport of VIEWPORTS) {
)
})
test('pinned: Delete and Insert from the keyboard keep the page still, the vertex below the strip', async ({
page,
}) => {
await open(page, ...manyPoints(), {
...pointOf('zone-k', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone K'),
kind: 'zone',
geometry: {
type: 'polygon',
points: [
[300, 600],
[300, 150],
[600, 150],
[600, 600],
],
},
})
await pickAnnotation(page, dict, 'Zone K')
await page.evaluate(() => window.scrollTo(0, 400))
// A pinned handle carries no strip margin: its focus does not scroll the page.
await page.locator('[data-vertex="0"]').focus()
const before = (await stripGeometry(page)).scrollY
expect(before, 'the focus on a pinned handle').toBe(400)
for (const [key, last] of [
['Delete', 0],
['Insert', 1],
] as const) {
await page.keyboard.press(key)
await expect(page.locator('[data-vertex="3"]')).toHaveCount(last)
const at = await focusedUnderStrip(page)
expect(at.name, key).toContain('Sommet')
expect(
at.top,
`${key}: ${at.name} below the strip`,
).toBeGreaterThanOrEqual((await stripGeometry(page)).bottom - 0.5)
expect((await stripGeometry(page)).scrollY, `${key}: the page`).toBe(
before,
)
}
})
test('pinned: a row selection moves neither the page nor the drawing on screen', async ({
page,
}) => {
await open(page, ...manyPoints())
for (const name of ['Pt 3', 'Pt 4']) {
const row = annotationList(page, dict).getByRole('button', { name })
// The row at mid-window, the page scrolled past the point where the column sticks.
await row.evaluate((el) => {
const top = el.getBoundingClientRect().top + window.scrollY
window.scrollTo(0, top - window.innerHeight / 2)
})
expect((await stripGeometry(page)).scrollY).toBeGreaterThan(300)
const box = (await row.boundingBox())!
const strip = await stripGeometry(page)
expect(box.y, `precondition: ${name} in view`).toBeGreaterThan(
strip.bottom,
)
expect(box.y + box.height).toBeLessThan(strip.innerHeight)
const before = await columnGeometry(page)
// A real pointer press on the visible row: no bring-into-view scroll.
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2)
await expect(selectionTag(page)).toContainText(name)
expect((await stripGeometry(page)).scrollY, name).toBe(strip.scrollY)
expect((await columnGeometry(page)).canvas, name).toEqual(before.canvas)
}
})
test('with the strip hidden only the bar offset is applied', async ({
page,
}) => {
@@ -1001,3 +1166,49 @@ for (const viewport of VIEWPORTS) {
})
})
}
// U2 Task 17 at shorter windows: 1 180 x 700 pins a capped canvas (its size set by the window,
// never by the scroll); 1 024 x 600 is below the pinned height (nothing pinned or capped).
const SHORT_WINDOWS = [
{ width: 1180, height: 700, pinned: true },
{ width: 1024, height: 600, pinned: false },
]
for (const { pinned, ...viewport } of SHORT_WINDOWS) {
test.describe(`the drawing column at ${viewport.width} x ${viewport.height} (U2 Task 17)`, () => {
test.use({ locale: 'fr-FR', actionTimeout: 15_000, viewport })
test.beforeEach(async ({ context }, info) => {
test.skip(isPhone(info), 'editing needs 1 024 px') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access
await routeToSandbox(context)
})
test.afterEach(async ({ context }) => {
await dropLateReplays(context)
})
test('no sideways scroll at any scroll step; pinned, the column fits the window', async ({
page,
}) => {
await open(page, ...manyPoints())
const start = await stripGeometry(page)
const { canvas, canvasFills } = await columnGeometry(page)
expect(canvasFills, 'the canvas is capped only when pinned').toBe(!pinned)
for (let y = 0; y <= start.limit + 150; y += 150) {
await page.evaluate((to) => window.scrollTo(0, to), y)
const strip = await stripGeometry(page)
const now = await columnGeometry(page)
const at = `scrollY ${strip.scrollY}`
expect(now.sideways, `no sideways scroll at ${at}`).toBe(false)
expect(now.canvas.width, `canvas width at ${at}`).toBe(canvas.width)
if (!pinned) continue
expect(
now.top,
`column below the strip at ${at}`,
).toBeGreaterThanOrEqual(strip.bottom - 0.5)
if (strip.top <= strip.barBottom + 0.5)
expect(now.bottom, `column in view at ${at}`).toBeLessThanOrEqual(
strip.innerHeight + 0.5,
)
}
})
})
}
+2 -3
View File
@@ -256,8 +256,6 @@ async function modifyAnnotations(page: Page) {
*/
async function repairGeometry(page: Page) {
await toolButton(page, dict, 'point').click()
// The last row click scrolled the page: the drawing's top edge is under the sticky strip.
await scrollToTop(page)
// On this 200 x 150 drawing the core keeps a shrunk marker at 1 unit from the edge: the
// proposal of a corrected position needs a click on the edge itself (editor-geometry
// covers it on a 1 000-unit drawing). Here the click is placed at once.
@@ -337,7 +335,8 @@ test.describe('editor journey (owner trial steps)', () => {
await historyButton(page, dict, 'undo').click()
await historyButton(page, dict, 'redo').click()
const modified = await modifyAnnotations(page)
// At rest: scrolled, the stuck strip covers part of the aside's targets (axe target-size).
// Scrolled, the side panel still passes under the strip (only the drawing column is
// pinned): a row under it fails axe's target-size. The scan runs at rest, at the top.
await scrollToTop(page)
await expectAccessible(page, 'the editor with annotations')
await saveDraft(page, dict, 1)
@@ -181,7 +181,7 @@ function CanvasBox({
const root = build.root?.viewId === viewId ? build.root : null
const cursor = tool === 'select' ? 'cursor-grab' : 'cursor-crosshair'
return (
<div className={BOX}>
<div data-canvas-box className={BOX}>
<div
ref={viewport}
tabIndex={0}
@@ -334,7 +334,7 @@ function CanvasColumn({
const { doc, dispatch, model } = scene
const noCategory = doc.categories.length === 0
return (
<div className="min-w-0 space-y-3">
<div data-drawing-column className="min-w-0 space-y-3">
<ViewSwitcher
views={doc.views}
current={scene.viewId}
+42
View File
@@ -11,6 +11,10 @@ body,
:root {
--shell-top-bar-height: calc(3.5rem + env(safe-area-inset-top, 0px));
--edit-strip-height: 4rem;
/* Where the pinned drawing column stops: under the strip and its gap (space-y-3). */
--edit-pinned-top: calc(
var(--shell-top-bar-height) + var(--edit-strip-height) + 0.75rem
);
}
/* The editor page's other focusables (header, tab row, history buttons, notices) are never
left under the sticky top bar either (criterion 25), at every width: the bar is sticky
@@ -56,6 +60,44 @@ body,
);
}
}
/* The drawing column (chips, tools, canvas, add row, message line) is pinned under the
strip, so no part of the drawing is ever under it while the side panel scrolls (U2 Task
17). Only where the column fits: below 40.25rem high the 365 px tool column beside a
capped canvas does not, and nothing here applies. The negative bottom margin lets the
pinned travel run into the page's bottom space (workspace gap + main padding): without
it, the page's end pushed the column's top under the strip at 1 180 x 820. */
@media (min-width: 1024px) and (min-height: 40.25rem) {
[data-drawing-column] {
position: sticky;
top: var(--edit-pinned-top);
align-self: start;
margin-bottom: -3rem;
}
/* The column fits the window: the 4:3 box's width is capped by the small viewport height
less the pinned top and the column's other parts (one row of chips, the add row, the
line, the gaps: 9.25rem), plus its 2 px border. svh: a toolbar collapsing during a
scroll never resizes the box. Unchanged at 1 024 x 768, 1 180 x 820, 1 280 x 800. */
[data-drawing-column] [data-canvas-box] {
max-width: calc((100svh - var(--edit-pinned-top) - 9.25rem) * 4 / 3 + 2px);
}
/* A pinned control is never under the strip: the strip's margin, larger than the pinned
top, made a focus on it scroll the page (Task 14's jump). The bar's margin stays. Same
specificity as the drawing place's rule, later: it wins. */
[data-place='annotations.drawing']:not([hidden])
[data-drawing-column]
:is(
a,
button,
input,
select,
textarea,
[tabindex],
[data-focus-key],
[data-focus-target]
) {
scroll-margin-top: calc(var(--shell-top-bar-height) + 0.5rem);
}
}
/* A modal dialog is open (components/ui/ModalDialog): the page behind it does not scroll. */
html:has(dialog:modal) {
overflow: hidden;
+21
View File
@@ -242,6 +242,27 @@ Backspace, Insert, « + ») takes the focus with a scroll, so the margin applies
one chosen by a pointer or a finger takes it without a scroll. Below 1 024 px
the strip is not sticky.
The drawing column (U2 Task 17: the view chips, the tools and the canvas box,
the add row, the message line; `data-drawing-column`) is pinned under the strip
from 1 024 px wide and 40.25 rem (644 px) high: `sticky` at
`--edit-pinned-top` (bar + strip + 0.75 rem, the strip's gap), aligned to the
start of its grid row, so no part of it ever passes under the strip or the bar
while the side panel scrolls past; the side panel still passes under the strip.
A bottom margin of −3 rem lets the pinned travel run into the page's bottom
space (the workspace's gap and the main area's padding), else the end of the
page pushed the column's top under the strip at 1 180 × 820. So that the column
always fits the window, the canvas box (`data-canvas-box`) is capped in width at
`(100svh − --edit-pinned-top − 9.25 rem) × 4/3 + 2 px` (9.25 rem: one row of
chips, one add row, the line and the gaps; 2 px: the box's border), keeping its
4:3 ratio: the cap follows the window's small viewport height, never the
scroll nor a collapsing browser toolbar, and leaves the box unchanged at
1 024 × 768, 1 180 × 820 and 1 280 × 800; a capped box sits left, with spare
width on its right. Its focusables carry only the bar's margin there (the
strip's margin, larger than the pinned top, would scroll the page on a focus of
a pinned control). Below 644 px high the tool column (365 px) no longer fits
beside a capped box: nothing is pinned or capped, and the drawing scrolls under
the strip as before, with the strip's margin on its focusables.
The editor page's other focusables (criterion 25: the header's « Enregistrer », the
tab row, « Défaire » and « Refaire », the notices' controls) carry a smaller margin,
the bar's height plus 0.5 rem, at every width since the bar is sticky everywhere. It