From 4e87974842c502894e7bb0fa67c6ec34d6155feb Mon Sep 17 00:00:00 2001 From: callumalpass Date: Sun, 29 Nov 2026 04:47:18 +1100 Subject: [PATCH 1/3] Reserve a full Scratchpad checkbox target and collapse inactive table controls --- e2e/scratchpad-table-targets.spec.ts | 111 ++++++++++++++++++++++ src/styles/16-scratchpad-live-preview.css | 56 ++++------- src/styles/17-scratchpad-note.css | 15 +-- 3 files changed, 134 insertions(+), 48 deletions(-) create mode 100644 e2e/scratchpad-table-targets.spec.ts diff --git a/e2e/scratchpad-table-targets.spec.ts b/e2e/scratchpad-table-targets.spec.ts new file mode 100644 index 00000000..0f0438e1 --- /dev/null +++ b/e2e/scratchpad-table-targets.spec.ts @@ -0,0 +1,111 @@ +import AxeBuilder from "@axe-core/playwright"; +import { expect, test } from "./local-test"; +import { outlineOf } from "./scratchpad-editor"; + +for (const [width, height, hasTouch] of [ + [1042, 662, false], + [1280, 800, false], + [390, 844, false], + [390, 844, true], +] as const) { + test.describe(`${width}×${height} ${hasTouch ? "coarse" : "fine"}`, () => { + test.use({ viewport: { width, height }, hasTouch }); + test("Scratchpad checkbox clears inactive and active table controls", async ({ + page, + }) => { + await page.goto("scratchpad/?demo=60"); + const current = page.locator(".scratchpad-current-document"); + const editor = outlineOf(current); + const checkbox = current.getByRole("checkbox").first(); + await expect(checkbox).toBeVisible(); + const controls = current.locator(".cm-lp-table-controls > button"); + await expect(controls).toHaveCount(4); + expect( + await controls.evaluateAll((buttons) => + buttons.map((button) => button.getAttribute("title")), + ), + ).toEqual(["Column options", "Row options", "Add row", "Add column"]); + const measure = () => + checkbox.evaluate((box) => { + const rect = box.getBoundingClientRect(); + const overlaps = Array.from( + box + .closest(".cm-editor")! + .querySelectorAll(".cm-lp-table-controls > button"), + ) + .filter((el) => { + const other = el.getBoundingClientRect(); + return ( + Math.min(rect.right, other.right) > + Math.max(rect.left, other.left) && + Math.min(rect.bottom, other.bottom) > + Math.max(rect.top, other.top) + ); + }) + .map((el) => el.getAttribute("title")); + return { + x: rect.x, + y: rect.y, + width: rect.width, + height: rect.height, + overlaps, + }; + }); + const inactive = await measure(); + await test + .info() + .attach("inactive geometry", { + body: JSON.stringify(inactive), + contentType: "application/json", + }); + expect + .soft(inactive, JSON.stringify(inactive)) + .toMatchObject({ width: 44, height: 44, overlaps: [] }); + await editor.fill( + "- [ ] Draft\n\n| Item | Value |\n| --- | --- |\n| One | Two |\n\n", + ); + await editor.getByText("One", { exact: true }).click(); + await expect( + current.locator(".cm-lp-table-controls-visible"), + ).toHaveCount(1); + for (const button of await controls.all()) { + await expect(button).toBeVisible(); + } + const active = await measure(); + await test + .info() + .attach("active geometry", { + body: JSON.stringify(active), + contentType: "application/json", + }); + expect(active).toMatchObject({ width: 44, height: 44, overlaps: [] }); + expect( + await page.evaluate( + () => document.documentElement.scrollWidth - innerWidth, + ), + ).toBeLessThanOrEqual(0); + for (const colorScheme of ["light", "dark"] as const) { + await page.emulateMedia({ colorScheme }); + await page.evaluate(async () => { + document.documentElement.getBoundingClientRect(); + await Promise.allSettled( + document + .getAnimations() + .filter( + (animation) => + animation.effect?.getTiming().iterations !== Infinity, + ) + .map((animation) => animation.finished), + ); + }); + expect( + ( + await new AxeBuilder({ page }) + .withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"]) + .analyze() + ).violations, + ).toEqual([]); + } + }); + }); +} diff --git a/src/styles/16-scratchpad-live-preview.css b/src/styles/16-scratchpad-live-preview.css index cb0c8618..1cb34a7e 100644 --- a/src/styles/16-scratchpad-live-preview.css +++ b/src/styles/16-scratchpad-live-preview.css @@ -48,24 +48,32 @@ position: relative; display: inline-block; box-sizing: border-box; - width: 17px; - height: 17px; + width: 44px; + height: 44px; margin: 0; padding: 0; - vertical-align: -3px; + vertical-align: middle; color: var(--paper); background: transparent; - border: 1.75px solid var(--ink-muted); - border-radius: 5px; + border: 0; cursor: pointer; + border-radius: 0; appearance: none; } -.markdown-source-editor .cm-lp-task:hover { +.markdown-source-editor .cm-lp-task::before { + position: absolute; + inset: 12px; + content: ""; + border: 1.75px solid var(--ink-muted); + border-radius: 5px; +} + +.markdown-source-editor .cm-lp-task:hover::before { border-color: var(--accent); } -.markdown-source-editor .cm-lp-task[aria-checked="true"] { +.markdown-source-editor .cm-lp-task[aria-checked="true"]::before { background: var(--accent); border-color: var(--accent); } @@ -137,37 +145,13 @@ color: var(--color-danger); } -@media (pointer: coarse), (max-width: 560px) { - /* Give the button its own column. Only the centred 20px box is painted. */ - .markdown-source-editor .cm-lp-task { - width: 44px; - height: 44px; - vertical-align: middle; - border: 0; - border-radius: 0; - background: transparent; - } - - .markdown-source-editor .cm-lp-task::before { - position: absolute; - inset: 12px; - content: ""; - border: 1.75px solid var(--ink-muted); - border-radius: 5px; - } - - .markdown-source-editor .cm-lp-task[aria-checked="true"] { - background: transparent; - } - - .markdown-source-editor .cm-lp-task[aria-checked="true"]::before { - background: var(--accent); - border-color: var(--accent); - } -} - @media (pointer: coarse) { .cm-lp-table-menu .mdbase-menu-item { min-height: 44px; } } + +/* The editor positions these buttons only while a table is active. */ +.scratchpad-note-text .cm-lp-table-controls:not(.cm-lp-table-controls-visible) { + display: none; +} diff --git a/src/styles/17-scratchpad-note.css b/src/styles/17-scratchpad-note.css index 739d627d..ed3a5686 100644 --- a/src/styles/17-scratchpad-note.css +++ b/src/styles/17-scratchpad-note.css @@ -18,7 +18,8 @@ } .scratchpad-note-text { - --scratch-line-pad: 3px; + --scratch-line-pad: 2px; + --scratch-marker-width: 44px; } .scratchpad-note-text .cm-line { @@ -100,6 +101,7 @@ } .scratchpad-note-text .cm-scratch-item { + min-height: 48px; --lp-list-indent: calc( var(--scratch-depth, 0) * var(--scratch-step) + var(--scratch-marker-width, var(--scratch-step)) @@ -323,17 +325,6 @@ } } -@media (pointer: coarse), (max-width: 560px) { - .scratchpad-note-text { - --scratch-line-pad: 2px; - --scratch-marker-width: 44px; - } - - .scratchpad-note-text .cm-scratch-item { - min-height: 48px; - } -} - @media (pointer: coarse) { .scratchpad-note-text .cm-gutters, .scratchpad-note-text .cm-scratch-fold-gutter, From 915d33a18e12ba207552710850e2df7f19833ec8 Mon Sep 17 00:00:00 2001 From: callumalpass Date: Sun, 29 Nov 2026 04:49:06 +1100 Subject: [PATCH 2/3] Apply stable formatting to geometry attachments --- e2e/scratchpad-table-targets.spec.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/e2e/scratchpad-table-targets.spec.ts b/e2e/scratchpad-table-targets.spec.ts index 0f0438e1..7203c946 100644 --- a/e2e/scratchpad-table-targets.spec.ts +++ b/e2e/scratchpad-table-targets.spec.ts @@ -52,12 +52,10 @@ for (const [width, height, hasTouch] of [ }; }); const inactive = await measure(); - await test - .info() - .attach("inactive geometry", { - body: JSON.stringify(inactive), - contentType: "application/json", - }); + await test.info().attach("inactive geometry", { + body: JSON.stringify(inactive), + contentType: "application/json", + }); expect .soft(inactive, JSON.stringify(inactive)) .toMatchObject({ width: 44, height: 44, overlaps: [] }); @@ -72,12 +70,10 @@ for (const [width, height, hasTouch] of [ await expect(button).toBeVisible(); } const active = await measure(); - await test - .info() - .attach("active geometry", { - body: JSON.stringify(active), - contentType: "application/json", - }); + await test.info().attach("active geometry", { + body: JSON.stringify(active), + contentType: "application/json", + }); expect(active).toMatchObject({ width: 44, height: 44, overlaps: [] }); expect( await page.evaluate( From 36e6809e9784e30f2c98c78ee8966a84dab9bd32 Mon Sep 17 00:00:00 2001 From: callumalpass Date: Sun, 29 Nov 2026 04:59:57 +1100 Subject: [PATCH 3/3] Wait for the applied Scratchpad theme before auditing contrast --- e2e/scratchpad-table-targets.spec.ts | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/e2e/scratchpad-table-targets.spec.ts b/e2e/scratchpad-table-targets.spec.ts index 7203c946..5b066db7 100644 --- a/e2e/scratchpad-table-targets.spec.ts +++ b/e2e/scratchpad-table-targets.spec.ts @@ -9,7 +9,11 @@ for (const [width, height, hasTouch] of [ [390, 844, true], ] as const) { test.describe(`${width}×${height} ${hasTouch ? "coarse" : "fine"}`, () => { - test.use({ viewport: { width, height }, hasTouch }); + test.use({ + viewport: { width, height }, + hasTouch, + reducedMotion: "reduce", + }); test("Scratchpad checkbox clears inactive and active table controls", async ({ page, }) => { @@ -82,18 +86,10 @@ for (const [width, height, hasTouch] of [ ).toBeLessThanOrEqual(0); for (const colorScheme of ["light", "dark"] as const) { await page.emulateMedia({ colorScheme }); - await page.evaluate(async () => { - document.documentElement.getBoundingClientRect(); - await Promise.allSettled( - document - .getAnimations() - .filter( - (animation) => - animation.effect?.getTiming().iterations !== Infinity, - ) - .map((animation) => animation.finished), - ); - }); + await expect(page.locator("html")).toHaveCSS( + "color-scheme", + colorScheme, + ); expect( ( await new AxeBuilder({ page })