From 5778d061910e4d24ae655e5b2c88b62c3ccd03b3 Mon Sep 17 00:00:00 2001 From: Fabio Date: Sun, 8 Nov 2026 07:52:19 -0300 Subject: [PATCH 01/17] fix: Alt+C closes a date field's calendar again Co-Authored-By: Claude Sonnet 5.5 --- src/ui/date-picker.ts | 20 +++++++++++++++++--- test/date-picker.test.ts | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/ui/date-picker.ts b/src/ui/date-picker.ts index d75befd..1681a1c 100644 --- a/src/ui/date-picker.ts +++ b/src/ui/date-picker.ts @@ -171,6 +171,13 @@ export function createDatePicker(opts: DatePickerOptions): DatePickerHandle { // the field: Tab cycles inside until a pick or Escape. wrap.addEventListener('keydown', (e) => { const ev = e as KeyboardEvent + // Alt+C opened it, so it closes it too, from inside the calendar where that chord left the focus. + if (isCalendarToggle(ev)) { + ev.preventDefault() + ev.stopPropagation() + closePopover() + return + } if (ev.key !== 'Tab') return const stops = Array.from(wrap.querySelectorAll('button')).filter((b) => b.tabIndex >= 0) const at = stops.indexOf(document.activeElement as HTMLElement) @@ -212,13 +219,20 @@ export function createDatePicker(opts: DatePickerOptions): DatePickerHandle { // Keys on the field. Up/Down step a day and t is today, from what the field // holds (today when empty); Alt+Down opens the calendar and goes into it, as - // on a native date field, and Alt+C does the same (the key that shows or hides - // the daily-notes calendar). Alt+Down is also the pane swap, so both stop here. + // on a native date field. Alt+C (the key that shows or hides the daily-notes + // calendar) toggles it: it opens and goes in, or closes an open one. Alt+Down + // is also the pane swap, so both stop here. + const isCalendarToggle = (e: KeyboardEvent): boolean => e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey && matchKey(e, 'c') function onFieldKeydown(e: KeyboardEvent): void { if (isReadOnlyLocked()) return - if (e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey && (e.key === 'ArrowDown' || matchKey(e, 'c'))) { + const toggle = isCalendarToggle(e) + if (toggle || (e.key === 'ArrowDown' && e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey)) { e.preventDefault() e.stopPropagation() + if (toggle && popover) { + closePopover() + return + } if (!popover) openPopover() popover?.querySelector('.tt-calendar-day[tabindex="0"]')?.focus() return diff --git a/test/date-picker.test.ts b/test/date-picker.test.ts index 9077f7d..f0bb99f 100644 --- a/test/date-picker.test.ts +++ b/test/date-picker.test.ts @@ -339,6 +339,27 @@ describe('keyboard', () => { handle.destroy() }) + test('Alt+C closes the calendar again, from the field or from inside it, with focus back on the field', () => { + const handle = mount({ value: '2026-07-20', locale: 'en-US', onChange: () => {} }) + input(handle).focus() + press(input(handle), { key: 'c', code: 'KeyC', altKey: true }) + expect(popover()).not.toBeNull() + const reached = vi.fn() + document.addEventListener('keydown', reached, { once: true }) + press(document.activeElement!, { key: 'c', code: 'KeyC', altKey: true }) + expect(popover()).toBeNull() + expect(document.activeElement).toBe(input(handle)) + expect(reached).not.toHaveBeenCalled() + document.removeEventListener('keydown', reached) + + // Opened by a click, focus stays on the field: Alt+C there closes it too. + input(handle).click() + expect(popover()).not.toBeNull() + press(input(handle), { key: 'c', code: 'KeyC', altKey: true }) + expect(popover()).toBeNull() + handle.destroy() + }) + test('picking by keyboard commits and puts focus back on the field', () => { const handle = mount({ value: '2026-07-20', locale: 'en-US', onChange: () => {} }) input(handle).focus() From 4fde4db048fc8932091c8922451ac559c6772aba Mon Sep 17 00:00:00 2001 From: Fabio Date: Sun, 8 Nov 2026 07:52:19 -0300 Subject: [PATCH 02/17] feat(help): Editor tab lists key tables first, prose sections last Co-Authored-By: Claude Sonnet 5.5 --- src/ui/help.ts | 5 +++-- test/help.test.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ui/help.ts b/src/ui/help.ts index 718b0c0..1bc1a71 100644 --- a/src/ui/help.ts +++ b/src/ui/help.ts @@ -256,11 +256,12 @@ const TABS: readonly TabDef[] = [ rowsSection(ctx, 'help_sec_blocks', blockRows), rowsSection(ctx, 'help_sec_links', linkRows(ctx.locale)), rowsSection(ctx, 'help_md_heading', mdRows(ctx.locale)), + rowsSection(ctx, 'help_sec_leave', [['Esc', 'help_notes_leave']]), + rowsSection(ctx, 'help_sec_history', historyRows), + // The key tables come first; the prose sections (what @, / and pasted pictures do) close the tab. textSection(ctx, 'help_refs_heading', 'help_refs_text'), textSection(ctx, 'help_templates_heading', 'help_templates_text'), textSection(ctx, 'help_images_heading', 'help_images_text'), - rowsSection(ctx, 'help_sec_leave', [['Esc', 'help_notes_leave']]), - rowsSection(ctx, 'help_sec_history', historyRows), ], }, { diff --git a/test/help.test.ts b/test/help.test.ts index 6114fc5..d4e031d 100644 --- a/test/help.test.ts +++ b/test/help.test.ts @@ -315,9 +315,9 @@ describe('Editor tab', () => { expect(text).not.toMatch(/texto|clique/) }) - test('groups the shortcuts by what they do and puts undo/redo last, not first', () => { + test('groups the shortcuts by what they do, key tables first and the prose sections last, undo/redo after the formatting keys', () => { showHelp('en-US', { tab: 'editor' }) - expect(headings()).toEqual(['Inline formatting', 'Blocks', 'Links', 'Markdown syntax', 'References (@)', 'Templates (/)', 'Pictures', 'Leaving the editor', 'History']) + expect(headings()).toEqual(['Inline formatting', 'Blocks', 'Links', 'Markdown syntax', 'Leaving the editor', 'History', 'References (@)', 'Templates (/)', 'Pictures']) const shortcuts = codes() expect(shortcuts[0]).toBe('Ctrl+B') const text = panelText() From 9147678413bf804f4de000b756fc5598a277a7c0 Mon Sep 17 00:00:00 2001 From: Fabio Date: Wed, 11 Nov 2026 20:25:28 -0300 Subject: [PATCH 03/17] fix(editor): plain-text paste mid-list-item no longer splits the item around the text Leading/trailing line breaks (a copied line usually ends in one) made Chromium's insertText split the item in three. Co-Authored-By: Claude Sonnet 5.5 --- src/ui/editor.ts | 4 +++- test/editor.test.ts | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ui/editor.ts b/src/ui/editor.ts index d04daf3..a4d83c8 100644 --- a/src/ui/editor.ts +++ b/src/ui/editor.ts @@ -2210,7 +2210,9 @@ export function createEditor(hooks: EditorHooks, locale: Locale): Editor { return } undoStack.checkpoint() - document.execCommand('insertText', false, text) + // Mid-item, a leading or trailing line break (a copied line usually ends in one) makes + // Chromium split the item, so the paste lands alone between two new items. + document.execCommand('insertText', false, selectionInListItem() ? text.replace(/^(?:\r?\n)+|(?:\r?\n)+$/g, '') : text) scheduleChange() } diff --git a/test/editor.test.ts b/test/editor.test.ts index fa72434..da782a3 100644 --- a/test/editor.test.ts +++ b/test/editor.test.ts @@ -228,6 +228,27 @@ describe('paste', () => { editor.destroy() }) + test('plain text pasted mid-list-item drops its leading/trailing line breaks (they would split the item around it)', () => { + const editor = createEditor(makeHooks(), 'en-US') + document.body.appendChild(editor.root) + editor.setMd('- item') + const execSpy = vi.spyOn(document, 'execCommand').mockReturnValue(true) + const li = editor.root.querySelector('.editor li')! + const range = document.createRange() + range.setStart(li.firstChild!, 2) + range.collapse(true) + const sel = window.getSelection()! + sel.removeAllRanges() + sel.addRange(range) + + dispatchPaste(editor, { 'text/plain': '\r\nPASTED\r\n' }) + dispatchPaste(editor, { 'text/plain': '\na\nb\n\n' }) + + const inserts = execSpy.mock.calls.filter((c) => c[0] === 'insertText') + expect(inserts).toEqual([['insertText', false, 'PASTED'], ['insertText', false, 'a\nb']]) + editor.destroy() + }) + test('inline styles the browser adds while inserting a paste are removed', () => { // Chromium puts the surrounding block's font on the inserted spans. vi.spyOn(document, 'execCommand').mockImplementation((cmd, _s, val) => { From 269a1af9fb0b484f012d4bb61b38eb51b6c015c5 Mon Sep 17 00:00:00 2001 From: Fabio Date: Wed, 11 Nov 2026 20:30:27 -0300 Subject: [PATCH 04/17] chore: bump version to 3.6.4 Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 9 +++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1350032..698c99b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ All notable changes to Team Tracker are documented here, written for people usin See [CLAUDE.md](CLAUDE.md#changelog) for how and when to update this file. +## [3.6.4] - 2026-11-11 + +### Changed +- The Editor tab of Help lists the key tables first and the prose sections last. + +### Fixed +- Pasting plain text in the middle of a list item no longer splits the item, with blank lines above and below the pasted text. +- Alt+C closes a date field's calendar again. + ## [3.6.3] - 2026-11-07 ### Added diff --git a/package-lock.json b/package-lock.json index bd5b28b..1d80cc0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "team-tracker", - "version": "3.6.3", + "version": "3.6.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "team-tracker", - "version": "3.6.3", + "version": "3.6.4", "license": "AGPL-3.0-only", "devDependencies": { "@axe-core/playwright": "^4.13.0", diff --git a/package.json b/package.json index fe165ac..1703526 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "team-tracker", - "version": "3.6.3", + "version": "3.6.4", "homepage": "https://fmpallini.github.io/team-tracker/", "repository": "fmpallini/team-tracker", "private": true, From 73e9e8b202f8320925fed737cc5745bf106b9748 Mon Sep 17 00:00:00 2001 From: Fabio Date: Wed, 11 Nov 2026 21:56:02 -0300 Subject: [PATCH 05/17] fix(editor): the space typed after a bold run or @-mention is no longer doubled After autoformatting **b** (or picking an @-mention) the editor parks the caret behind a non-breaking space of its own; the space the user typed next landed after it, so the note showed and saved two. That space is now absorbed once. Found by the new e2e/editor-scenarios.spec.ts: editing behavior as a table of start note (with a caret marker), steps, and the markdown the app saves, run in real Chromium where jsdom cannot reach (paste, undo, list structure). Co-Authored-By: Claude Opus 5.5 --- e2e/editor-scenarios.spec.ts | 175 +++++++++++++++++++++++++++++++++++ src/ui/editor-dom.ts | 18 ++++ src/ui/editor.ts | 7 +- test/editor.test.ts | 26 ++++++ 4 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 e2e/editor-scenarios.spec.ts diff --git a/e2e/editor-scenarios.spec.ts b/e2e/editor-scenarios.spec.ts new file mode 100644 index 0000000..0fa80cd --- /dev/null +++ b/e2e/editor-scenarios.spec.ts @@ -0,0 +1,175 @@ +// e2e/editor-scenarios.spec.ts — editing behavior as a table, in real Chromium. +// +// test/editor.test.ts runs under jsdom, which has no document.execCommand, no +// real selection model and no layout, so most of the editor's bugs (paste, +// undo, list structure, autoformat) can only be seen here. Each row is: the +// note as it starts (markdown, with ‸ marking the caret — two of them mark a +// selection), the steps a user takes, and the markdown the app SAVES — read +// back from the browser copy, the same bytes the file gets. Adding a +// regression is one row. +// +// Step strings are typed; press()/paste()/pasteHtml()/waitFor() build the others. +import { test, expect, type Page } from '@playwright/test' +import { openDoc } from './layout-fixtures' +import { flushLiveCopy } from './helpers' +import { createEmptyDocument, createEmptyTeam } from '../src/core/document' +import type { Doc } from '../src/core/types' + +const TEAM = 'team-0' +const TODAY = new Date().toLocaleDateString('en-CA') +const CARET = '‸' + +type Step = string | { press: string } | { paste: Record } | { wait: string } +const press = (key: string): Step => ({ press: key }) +const paste = (text: string): Step => ({ paste: { 'text/plain': text } }) +const pasteHtml = (html: string, text: string): Step => ({ paste: { 'text/html': html, 'text/plain': text } }) +/** Waits for `selector` to be visible (a picker opening on what was typed). */ +const waitFor = (selector: string): Step => ({ wait: selector }) + +interface Row { + name: string + /** + * The note before the steps; ‸ is the caret, two ‸ a selection. Empty: an empty note, caret in it. It loads as + * markdown, so a space at the end of a line is not kept — type it as a step instead. + */ + start: string + steps: Step[] + /** The note's saved markdown afterwards. */ + saved: string +} + +const ROWS: Row[] = [ + // --- typing and autoformat -------------------------------------------------- + { name: '"- " starts a bulleted list, Enter continues it', start: '', steps: ['- one', press('Enter'), 'two'], saved: '- one\n- two' }, + { name: '"1. " starts a numbered list', start: '', steps: ['1. a', press('Enter'), 'b'], saved: '1. a\n2. b' }, + { name: '"> " starts a quote', start: '', steps: ['> q'], saved: '> q' }, + // The editor parks the caret after the bold in a space of its own; the space typed next is that one, not a second. + { name: '"**x**" becomes bold as the closing marker is typed, and the next space is not doubled', start: '', steps: ['a **b** c'], saved: 'a **b** c' }, + { name: 'two spaces typed after the bold stay two', start: '', steps: ['a **b** c'], saved: 'a **b** c' }, + { name: 'an @-mention picked from the list, then a space and a word: one space', start: '', steps: ['see @Ana', waitFor('.tt-atref-dropdown'), press('Enter'), ' x'], saved: 'see @[Ana](person:p1) x' }, + { name: '"# " on the line under text makes THAT line a heading', start: `above${CARET}`, steps: [press('Enter'), '# Title'], saved: 'above\n# Title' }, + { name: 'Ctrl+1 on a blank line under text makes that line a heading', start: `text${CARET}`, steps: [press('Enter'), press('Control+1'), 'H'], saved: 'text\n# H' }, + { name: 'Ctrl+B bolds the selected word', start: `a ${CARET}word${CARET} b`, steps: [press('Control+b')], saved: 'a **word** b' }, + + // --- list structure --------------------------------------------------------- + { name: 'Enter mid-item splits the item', start: `- ab${CARET}cd`, steps: [press('Enter')], saved: '- ab\n- cd' }, + { name: 'Enter on an empty item ends the list', start: `- a${CARET}`, steps: [press('Enter'), press('Enter'), 'p'], saved: '- a\np' }, + { name: 'Tab nests an item', start: `- a\n- b${CARET}`, steps: [press('Tab')], saved: '- a\n - b' }, + { name: 'Shift+Tab lifts a nested item', start: `- a\n - b${CARET}`, steps: [press('Shift+Tab')], saved: '- a\n- b' }, + { name: 'Enter on the empty last line of a quote leaves the quote', start: `> q${CARET}`, steps: [press('Enter'), press('Enter'), 'after'], saved: '> q\nafter' }, + + // --- paste ------------------------------------------------------------------ + { name: 'plain text pasted mid-item stays inside the item', start: `- ab${CARET}cd`, steps: [paste('XY')], saved: '- abXYcd' }, + { name: 'plain text pasted mid-paragraph', start: `ab${CARET}cd`, steps: [paste('XY')], saved: 'abXYcd' }, + { name: 'an HTML list pasted into an empty note becomes a real list', start: '', steps: [pasteHtml('
  • one
  • two
', 'one\ntwo')], saved: '- one\n- two' }, + { name: 'blocks inside one pasted list item save as sibling items', start: '', steps: [pasteHtml('
  • a

    b

', 'a\nb')], saved: '- a\n- b' }, + { name: 'styled HTML pasted into a heading keeps a plain heading', start: `# He${CARET}ad`, steps: [pasteHtml('X', 'X')], saved: '# HeXad' }, + { name: 'HTML pasted inside a code block lands as its literal text', start: `\`\`\`\ncode${CARET}\n\`\`\``, steps: [pasteHtml('bold', 'bold')], saved: '```\ncodebold\n```' }, + + // --- undo / redo ------------------------------------------------------------ + { name: 'Ctrl+Z takes a paste back', start: `ab${CARET}`, steps: [paste('XY'), press('Control+z')], saved: 'ab' }, + { name: 'Ctrl+Z takes a Tab back', start: `- a\n- b${CARET}`, steps: [press('Tab'), press('Control+z')], saved: '- a\n- b' }, + { name: 'Ctrl+Shift+Z redoes the Tab', start: `- a\n- b${CARET}`, steps: [press('Tab'), press('Control+z'), press('Control+Shift+z')], saved: '- a\n - b' }, +] + +function noteDoc(note: string): Doc { + const doc = createEmptyDocument('en-US') + const team = createEmptyTeam(TEAM, 'Team', '📝', 'en-US') + team.dailyNotes[TODAY] = note + team.members.push({ id: 'p1', name: 'Ana', role: '', parentId: null, order: 0, notes: '' }) + doc.teams.push(team) + doc.nav.activeTeamId = TEAM + doc.nav.panes = [{ history: [{ teamId: TEAM, ref: { kind: 'daily', date: TODAY } }], index: 0 }, { history: [], index: -1 }] + return doc +} + +/** Focuses the editor and turns its ‸ markers into the selection (an empty note: caret in its first block). */ +async function placeCaret(page: Page): Promise { + await page.evaluate((mark) => { + const ed = document.querySelector('.editor')! + ed.focus() + const points: Array<[Node, number]> = [] + const walker = document.createTreeWalker(ed, NodeFilter.SHOW_TEXT) + const nodes: Text[] = [] + for (let n = walker.nextNode(); n; n = walker.nextNode()) nodes.push(n as Text) + // Last marker first, so removing it leaves the earlier offsets valid. + for (const node of nodes.reverse()) { + for (let i = node.data.lastIndexOf(mark); i !== -1; i = node.data.lastIndexOf(mark, i - 1)) { + node.deleteData(i, mark.length) + points.unshift([node, i]) + if (i === 0) break + } + } + for (const [node] of points) { + const block = node.parentElement! + if (block.textContent === '' && !block.querySelector('br')) block.appendChild(document.createElement('br')) + } + const range = document.createRange() + if (points.length === 0) { + range.selectNodeContents(ed.firstElementChild ?? ed) + range.collapse(true) + } else { + const [a, b] = [points[0]!, points[points.length - 1]!] + const at = (p: [Node, number]): [Node, number] => ((p[0] as Text).data === '' ? [p[0].parentElement!, 0] : p) + range.setStart(...at(a)) + range.setEnd(...at(b)) + } + const sel = getSelection()! + sel.removeAllRanges() + sel.addRange(range) + }, CARET) +} + +/** A real paste event at the current selection: the app reads only `clipboardData`, and its execCommand is the browser's. */ +async function dispatchPaste(page: Page, data: Record): Promise { + await page.evaluate((data) => { + const dt = new DataTransfer() + for (const [type, value] of Object.entries(data)) dt.setData(type, value) + document.querySelector('.editor')!.dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true })) + }, data) +} + +/** The note as the browser copy holds it once the editors and the store are flushed (plain document: rows are JSON text). */ +async function savedNote(page: Page): Promise { + await flushLiveCopy(page) + return page.evaluate(async (path) => { + const db: IDBDatabase = await new Promise((resolve, reject) => { + const req = indexedDB.open('team-tracker-live') + req.onsuccess = () => resolve(req.result) + req.onerror = () => reject(req.error ?? new Error('open failed')) + }) + const rows: unknown[] = await new Promise((resolve, reject) => { + const r = db.transaction('records', 'readonly').objectStore('records').getAll() + r.onsuccess = () => resolve(r.result as unknown[]) + r.onerror = () => reject(r.error ?? new Error('read failed')) + }) + db.close() + const seen: string[] = [] + // live-db.ts: { docId, key, value }, where a plain document's value is { t: JSON text of { path, value } }. + for (const row of rows) { + const text = ((row as { value?: { t?: unknown } }).value)?.t + if (typeof text !== 'string') { seen.push(JSON.stringify(row).slice(0, 80)); continue } + const rec = JSON.parse(text) as { path: string; value: unknown } + if (rec.path === path) return String(rec.value) + seen.push(rec.path) + } + throw new Error(`no saved record ${path}; found: ${seen.join(', ')}`) + }, `team/${TEAM}/daily/${TODAY}`) +} + +test.describe('editor scenarios (real browser, saved markdown)', () => { + for (const row of ROWS) { + test(row.name, async ({ page }) => { + await openDoc(page, noteDoc(row.start)) + await expect(page.locator('.editor').first()).toBeVisible() + await placeCaret(page) + for (const step of row.steps) { + if (typeof step === 'string') await page.keyboard.type(step) + else if ('press' in step) await page.keyboard.press(step.press) + else if ('wait' in step) await expect(page.locator(step.wait)).toBeVisible() + else await dispatchPaste(page, step.paste) + } + expect(await savedNote(page)).toBe(row.saved) + }) + } +}) diff --git a/src/ui/editor-dom.ts b/src/ui/editor-dom.ts index 332cdef..bfa32c8 100644 --- a/src/ui/editor-dom.ts +++ b/src/ui/editor-dom.ts @@ -73,6 +73,7 @@ export function caretAfterInline(node: ChildNode, gap: 'auto' | 'always' | 'none const r = document.createRange() if (gap === 'always' || (gap === 'auto' && !hasFollowingText)) { const slot = document.createTextNode('\u00a0') + gapSlots.add(slot) node.after(slot) r.setStart(slot, 1) } else { @@ -83,6 +84,23 @@ export function caretAfterInline(node: ChildNode, gap: 'auto' | 'always' | 'none sel.addRange(r) } +/** The NBSP slots caretAfterInline inserted — a space the editor typed on the user's behalf. */ +const gapSlots = new WeakSet() + +/** + * True when the caret sits right after a gap slot still holding only its NBSP, and forgets that slot: the space + * the user types next (after `**b**`, after an @-chip) is the one the gap already is, so the caller drops it — + * otherwise the note shows, and saves, two spaces. Only once: a second space is a real one. + */ +export function absorbGapSpace(): boolean { + const sel = window.getSelection() + if (!sel || !sel.isCollapsed || sel.rangeCount === 0) return false + const { startContainer, startOffset } = sel.getRangeAt(0) + if (!(startContainer instanceof Text) || !gapSlots.has(startContainer)) return false + gapSlots.delete(startContainer) + return startContainer.data === ' ' && startOffset === 1 +} + /** Builds a Range spanning text offsets [start, end) within `block`'s text content. */ export function rangeForTextOffsets(block: HTMLElement, start: number, end: number): Range { const range = document.createRange() diff --git a/src/ui/editor.ts b/src/ui/editor.ts index a4d83c8..69693a4 100644 --- a/src/ui/editor.ts +++ b/src/ui/editor.ts @@ -10,7 +10,7 @@ import { showHelp } from './help' import { showModal, toast } from './modal' import { paintSelection, clampMove, selectableRowProps } from './select-list' import { blockedByModal, matchKey } from './hotkeys' -import { blockAndCaret, caretAfterInline, rangeForTextOffsets, createRefChip, normalizeImageSpacing, type BlockCtx } from './editor-dom' +import { absorbGapSpace, blockAndCaret, caretAfterInline, rangeForTextOffsets, createRefChip, normalizeImageSpacing, type BlockCtx } from './editor-dom' import { createUndoStack, registerUndo, unregisterUndo } from './editor-undo' import { icon, iconButton } from './icons' import type { ImageHost } from './image-host' @@ -1738,6 +1738,11 @@ export function createEditor(hooks: EditorHooks, locale: Locale): Editor { return } if (e.defaultPrevented) return + // The space right after an autoformat/@-chip gap is already there (editor-dom.ts's absorbGapSpace). + if (e.inputType === 'insertText' && e.data === ' ' && absorbGapSpace()) { + e.preventDefault() + return + } undoStack.handleBeforeInput(e) } diff --git a/test/editor.test.ts b/test/editor.test.ts index da782a3..705625f 100644 --- a/test/editor.test.ts +++ b/test/editor.test.ts @@ -3585,6 +3585,32 @@ describe('inline auto-format caret exit', () => { editor.destroy() }) + test('the space typed right after the gap is the gap: it is absorbed once, and the next space is real', () => { + const { editor, editorEl } = mountAt('en-US', '
a **b**
') + editorEl.dispatchEvent(new Event('input', { bubbles: true })) + const space = (): InputEvent => { + const e = new InputEvent('beforeinput', { inputType: 'insertText', data: ' ', bubbles: true, cancelable: true }) + editorEl.dispatchEvent(e) + return e + } + expect(space().defaultPrevented).toBe(true) + expect(space().defaultPrevented).toBe(false) + editor.destroy() + }) + + test('a gap the user already typed past absorbs nothing', () => { + const { editor, editorEl } = mountAt('en-US', '
a **b**
') + editorEl.dispatchEvent(new Event('input', { bubbles: true })) + const slot = editorEl.querySelector('strong')!.nextSibling as Text + slot.data = ' c' + const r = document.createRange(); r.setStart(slot, 2); r.collapse(true) + const s = window.getSelection()!; s.removeAllRanges(); s.addRange(r) + const e = new InputEvent('beforeinput', { inputType: 'insertText', data: ' ', bubbles: true, cancelable: true }) + editorEl.dispatchEvent(e) + expect(e.defaultPrevented).toBe(false) + editor.destroy() + }) + test('typing **b** with text still after the caret adds no gap (would be a spurious space)', () => { const { editor, editorEl } = mountAt('en-US', '
a **b** tail
', 5) // caret right after the closing ** editorEl.dispatchEvent(new Event('input', { bubbles: true })) From 508dc0ac0b079eb6261b9537f9aff04c8d2a015e Mon Sep 17 00:00:00 2001 From: Fabio Date: Wed, 11 Nov 2026 21:56:02 -0300 Subject: [PATCH 06/17] fix(a11y): axe scans every module and overlay in both themes; fix what they found - fast switch is a named modal dialog; assignee input, column grip and the milestone timeline (now a Tab stop) get accessible names - tag chips say their count; the "TT" app name starts with what it shows; the F-key badge on module tabs is drawn by CSS so it is not read as label text - tag chip text picks black or white per card color (core/card-ink.ts): white failed AA in 23 of 24 palette x theme pairs; unselected chips desaturate instead of fading - due pills, danger button and muted text on selected rows reach 4.5:1 Co-Authored-By: Claude Opus 5.5 --- e2e/a11y.spec.ts | 87 +++++++++++++++++++++++++++++++++---- src/core/card-ink.ts | 34 +++++++++++++++ src/core/i18n.ts | 4 ++ src/modules/action-items.ts | 12 +++-- src/modules/milestones.ts | 4 +- src/ui/palette.ts | 2 +- src/ui/panes.ts | 4 +- src/ui/shell.ts | 10 ++++- styles.css | 38 ++++++++++------ test/action-items.test.ts | 16 ++++++- test/card-ink.test.ts | 47 ++++++++++++++++++++ test/palette.test.ts | 9 ++++ test/panes.test.ts | 4 +- test/shell.test.ts | 22 ++++++++++ 14 files changed, 260 insertions(+), 33 deletions(-) create mode 100644 src/core/card-ink.ts create mode 100644 test/card-ink.test.ts diff --git a/e2e/a11y.spec.ts b/e2e/a11y.spec.ts index 094bfcc..6bea6c5 100644 --- a/e2e/a11y.spec.ts +++ b/e2e/a11y.spec.ts @@ -1,7 +1,8 @@ -// e2e/a11y.spec.ts — automated accessibility scan (axe-core) of the three -// surfaces a keyboard-driven app most needs to keep clean: the start screen, -// the main shell with a document open, and an open modal dialog. Nothing else -// in the suite checks ARIA roles/names, focus semantics, or contrast. +// e2e/a11y.spec.ts — automated accessibility scan (axe-core): the start +// screen, the main shell, every module with real content in it, and the +// overlays a keyboard user lives in (Settings, fast switch, Help, the card +// editor). Nothing else in the suite checks ARIA roles/names, focus +// semantics, or contrast. // // Served over http://localhost (secure context) via the OPFS picker shim, the // same setup fs-api.spec.ts uses, so the real create → shell flow runs. @@ -10,10 +11,39 @@ import AxeBuilder from '@axe-core/playwright' import { E2E_BASE_URL } from '../playwright.config' import { installOpfsPickerShim } from './opfs-shim' import { createEncryptedDoc, blockUpdateCheck } from './helpers' +import { buildDoc, openDoc, TEAM_ID } from './layout-fixtures' +import type { Doc, ModuleRef } from '../src/core/types' + +const TODAY = new Date().toLocaleDateString('en-CA') + +type Theme = 'light' | 'dark' +const THEMES: Theme[] = ['light', 'dark'] + +/** layout-fixtures' busy document (some tasks due today, the rest overdue), plus the note content its builder leaves empty. */ +function contentDoc(ref: ModuleRef, theme: Theme = 'light'): Doc { + const doc = buildDoc('medium', ref, { stakeholderRoots: 3, milestones: 'spread', dueToday: true }) + doc.prefs.theme = theme + const team = doc.teams.find((t) => t.id === TEAM_ID)! + const note = '# Weekly sync\n\n- **Decision**: ship on Friday\n- Follow up with [link](https://example.com)\n\n> Quote\n\n```\ncode()\n```' + team.dailyNotes[TODAY] = note + team.generalNotes = note + team.stakeholders[0]!.notes = note + team.risks[0]!.followup = note + team.milestones[0]!.followup = note + return doc +} // WCAG 2 A/AA is the bar; scope each scan to the surface under test. -const scan = (page: Page, selector: string) => - new AxeBuilder({ page }).withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']).include(selector).analyze() +const scan = (page: Page, selector: string, skipRules: string[] = []) => + new AxeBuilder({ page }).withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']).include(selector).disableRules(skipRules).analyze() + +/** One line per offending node (`rule: selector — html`), so a failure reads at a glance instead of as axe's raw dump. */ +const violations = (results: Awaited>): string[] => + results.violations.flatMap((v) => v.nodes.map((n) => { + const c = n.any[0]?.data as { fgColor?: string; bgColor?: string; contrastRatio?: number } | null | undefined + const ratio = c?.contrastRatio ? ` [${c.fgColor} on ${c.bgColor} = ${c.contrastRatio}]` : '' + return `${v.id}: ${n.target.join(' ')}${ratio} — ${n.html.slice(0, 140)}` + })) test.describe('accessibility (axe-core)', () => { test('start screen has no WCAG A/AA violations', async ({ page }) => { @@ -23,7 +53,7 @@ test.describe('accessibility (axe-core)', () => { await expect(page.locator('.tt-start-screen')).toBeVisible() const results = await scan(page, '.tt-start-screen') - expect(results.violations).toEqual([]) + expect(violations(results)).toEqual([]) }) test('main shell (document open, first team created) has no WCAG A/AA violations', async ({ page }) => { @@ -39,7 +69,7 @@ test.describe('accessibility (axe-core)', () => { await teamDialog.waitFor({ state: 'hidden' }) const results = await scan(page, '.tt-shell') - expect(results.violations).toEqual([]) + expect(violations(results)).toEqual([]) }) test('the Settings modal has no WCAG A/AA violations', async ({ page }) => { @@ -53,6 +83,45 @@ test.describe('accessibility (axe-core)', () => { await expect(dialog).toBeVisible() const results = await scan(page, '.tt-modal-overlay') - expect(results.violations).toEqual([]) + expect(violations(results)).toEqual([]) }) + + const MODULES: Array<[string, ModuleRef]> = [ + ['daily notes', { kind: 'daily', date: TODAY }], + ['general notes', { kind: 'general' }], + ['stakeholders', { kind: 'stakeholders' }], + ['members (empty)', { kind: 'members' }], + ['person notes', { kind: 'person', personId: 's0', group: 'stakeholders' }], + ['tasks (kanban)', { kind: 'actions' }], + ['milestones', { kind: 'milestones' }], + ['risks', { kind: 'risks' }], + ] + // Both themes: contrast is a per-theme property, and the default palette is what most users run. + for (const theme of THEMES) { + for (const [name, ref] of MODULES) { + test(`the ${name} module has no WCAG A/AA violations (${theme})`, async ({ page }) => { + await openDoc(page, contentDoc(ref, theme)) + await expect(page.locator('.tt-pane-body').first()).not.toBeEmpty() + const results = await scan(page, '.tt-shell') + expect(violations(results)).toEqual([]) + }) + } + + const OVERLAYS: Array<[string, ModuleRef, (page: Page) => Promise, string, string[]]> = [ + // The result list scrolls without being a Tab stop: focus stays in the input, whose arrows move the selection + // and scroll it into view. (It still lacks combobox/listbox semantics — a known gap, not hidden by this.) + ['the fast switch', { kind: 'daily', date: TODAY }, (page) => page.keyboard.press('Control+Shift+K'), '.tt-palette-overlay', ['scrollable-region-focusable']], + ['Help', { kind: 'daily', date: TODAY }, (page) => page.keyboard.press('F1'), '.tt-modal-overlay', []], + ['the task editor', { kind: 'actions' }, (page) => page.locator('.tt-kanban-card').first().dblclick(), '.tt-modal-overlay', []], + ] + for (const [name, ref, open, overlay, skipRules] of OVERLAYS) { + test(`${name} has no WCAG A/AA violations (${theme})`, async ({ page }) => { + await openDoc(page, contentDoc(ref, theme)) + await open(page) + await expect(page.getByRole('dialog')).toBeVisible() + const results = await scan(page, overlay, skipRules) + expect(violations(results)).toEqual([]) + }) + } + } }) diff --git a/src/core/card-ink.ts b/src/core/card-ink.ts new file mode 100644 index 0000000..347f8f2 --- /dev/null +++ b/src/core/card-ink.ts @@ -0,0 +1,34 @@ +// src/core/card-ink.ts — text color for labels drawn on a solid card color +// (the task tag chips). The six --card-* colors are mid-tones in most light +// palettes: brass wants dark text and slate wants white, so no single ink per +// palette reaches WCAG AA on all six (white on brass was ~3.5:1 in most light +// palettes, with a text-shadow as the only crutch). Each fill instead gets +// whichever of pure white or pure black contrasts more with it — for any color +// that is at least ~4.58:1. Read from the computed style, like +// theme-color.ts, so every palette x theme pair resolves without a copied table. + +export const CARD_COLORS = ['slate', 'brass', 'sage', 'rust', 'plum', 'ledger'] as const + +const channel = (v: number): number => (v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4) + +/** `#ffffff` or `#000000`, whichever contrasts more with `fill` (a 6-digit hex); null when `fill` is not one. */ +export function inkFor(fill: string): '#ffffff' | '#000000' | null { + const digits = /^#([0-9a-f]{6})$/i.exec(fill.trim())?.[1] + if (!digits) return null + const n = parseInt(digits, 16) + const [r, g, b] = [(n >> 16) & 255, (n >> 8) & 255, n & 255].map((v) => channel(v / 255)) as [number, number, number] + const lum = 0.2126 * r + 0.7152 * g + 0.0722 * b + // Contrast with white is 1.05 / (lum + .05), with black (lum + .05) / .05: white wins below their crossover. + return 1.05 / (lum + 0.05) >= (lum + 0.05) / 0.05 ? '#ffffff' : '#000000' +} + +/** Sets `--on-card-` on the root for the active palette x theme; colors the stylesheet does not define keep its default. */ +export function syncCardInk(doc: Document = document): void { + const root = doc.documentElement + const style = getComputedStyle(root) + for (const c of CARD_COLORS) { + const ink = inkFor(style.getPropertyValue(`--card-${c}`)) + if (ink) root.style.setProperty(`--on-card-${c}`, ink) + else root.style.removeProperty(`--on-card-${c}`) + } +} diff --git a/src/core/i18n.ts b/src/core/i18n.ts index 6a1e9b9..b5f03d6 100644 --- a/src/core/i18n.ts +++ b/src/core/i18n.ts @@ -207,6 +207,7 @@ sidebar_teams_heading: 'Times', milestone_done_title: 'Concluído', milestone_pending_title: 'Pendente', milestone_delete_title: 'Excluir marco', + milestone_timeline_label: 'Linha do tempo dos marcos', milestone_deleted_toast: 'Marco "{title}" excluído', milestone_empty: 'Nenhum marco ainda. Adicione as datas que o time está perseguindo.', risk_add_btn: '+ Risco', @@ -267,6 +268,7 @@ sidebar_teams_heading: 'Times', empty_no_teams_hint: 'Cada time guarda notas diárias, pessoas, tarefas, marcos e riscos.', toast_focus_other: 'Já aberto no outro painel — focando nele', toast_person_not_found: 'Pessoa não encontrada', + palette_title: 'Troca rápida', palette_placeholder: 'Buscar em todos os times: módulo, pessoa, tarefa, marco ou risco… (Ctrl+Shift+K)', switcher_favorites: 'Favoritos', switcher_due: 'Prazos', @@ -912,6 +914,7 @@ sidebar_teams_heading: 'Teams', milestone_done_title: 'Done', milestone_pending_title: 'Pending', milestone_delete_title: 'Delete milestone', + milestone_timeline_label: 'Milestone timeline', milestone_deleted_toast: 'Milestone "{title}" deleted', milestone_empty: 'No milestones yet. Add the dates the team is working toward.', risk_add_btn: '+ Risk', @@ -965,6 +968,7 @@ sidebar_teams_heading: 'Teams', empty_no_teams_hint: 'Every team holds daily notes, people, tasks, milestones and risks.', toast_focus_other: 'Already open in the other pane — focusing it', toast_person_not_found: 'Person not found', + palette_title: 'Fast switch', palette_placeholder: 'Search every team: module, person, task, milestone or risk… (Ctrl+Shift+K)', switcher_favorites: 'Favorites', switcher_due: 'Due dates', diff --git a/src/modules/action-items.ts b/src/modules/action-items.ts index 44c3b23..25ae1d0 100644 --- a/src/modules/action-items.ts +++ b/src/modules/action-items.ts @@ -205,8 +205,12 @@ export const renderActionItems = withDisposal((container: HTMLElement, loc: Loc, // space, and an unnamed color needs it most: the swatch alone says // nothing about whether clicking it is worth the trip. if (counts[c] > 0) { + // The space is invisible in the flex chip but keeps "Blocked" and "3" apart in the text a reader gets. + if (custom !== null) children.push(' ') children.push(el('span', { class: 'tt-kanban-tag-chip-count' }, String(counts[c]))) } + // The name says the count too (screen readers got the tag alone), and contains everything drawn (WCAG 2.5.3). + const chipName = custom ?? suggestedTagName(c) const chip = el( 'button', { @@ -214,7 +218,7 @@ export const renderActionItems = withDisposal((container: HTMLElement, loc: Loc, // Same square swatch pattern as the color picker in the card modal // (.tt-kanban-color-chip) — blank until named, name shown inside once it is. class: `tt-kanban-color-chip tt-kanban-tag-chip color-${c}` + (activeTagFilter === c ? ' selected' : ''), - 'aria-label': custom ?? suggestedTagName(c), + 'aria-label': counts[c] > 0 ? `${chipName} ${counts[c]}` : chipName, 'aria-pressed': activeTagFilter === c ? 'true' : 'false', onclick: () => { activeTagFilter = activeTagFilter === c ? null : c @@ -440,7 +444,8 @@ export const renderActionItems = withDisposal((container: HTMLElement, loc: Loc, } const input = el('input', { - type: 'text', class: 'tt-input tt-assignee-input', autocomplete: 'off', value, + // The field's caption is a bare text node beside it, not a