diff --git a/docs/design-decisions.md b/docs/design-decisions.md index fd27460..7891898 100644 --- a/docs/design-decisions.md +++ b/docs/design-decisions.md @@ -950,3 +950,18 @@ Native shell, background image, and desktop acceptance remain open. - Evidence: `tests/smoke/layout/titleBar.smoke.mjs` and the Rust command list test. - Replaces / replaced by: The left pane footer, and the ribbon rule "The ribbon has no width when it has no entries." - Limits: Browser checks use desktop service mocks. Snap Layouts, the native drag area, and the macOS title bar need native acceptance. The macOS code path was not compiled here. On Windows 10, Win+Z does nothing. + +### UI-051 — Check marks, focus rings, and control states + +- Type: Rule change +- Date: 2026-10-28 +- Status: Implemented for user review +- Decision source: Owner decisions 8 and 13 (keyboard and focus) of 2026-10-27 (interface review issues 4 and 14, and finding 2 on UI-003), stage 5-5. +- Previous rule: The current radio row had the hover fill and no check mark, so a hovered row and the current row looked the same. Hover and keyboard focus shared one fill. Hover and active toggles shared one look. Disabled controls faded to 40 to 50% opacity (2.46:1 in light). The focus ring was 1 pixel and inset. Every file tree row was a Tab stop, and the tree had no arrow keys. Splitters took no keyboard focus. +- New rule: The current radio row shows a check mark in the icon column and no fill. Keyboard focus adds a 2-pixel ring to the shared hover fill. Active toggles get the accent color, the selection fill, and a 2-pixel accent bar. Disabled controls use `--rs-text-dim` at full opacity, and enabled icon buttons use `--rs-text`. The global focus ring is 2 pixels with a 1-pixel offset. The file tree has one Tab stop, arrow keys, Home, End, and type-ahead. Splitters take focus and move by 16 pixels with the arrow keys. Help names Esc, then Tab, to leave the text. +- Reason: The current choice, the pointer, and the keyboard focus must each be visible on their own. Disabled text must stay readable. +- Scope: Shared menus and pickers, icon buttons, all disabled buttons, the file tree, and the workbench splitters. +- Shared implementation: `actionMenu.ts` (the check mark), `menu.css`, `base.css`, `IconButton.svelte`, `FileTree.svelte`, `TreeNode.svelte`, and `splitterKey` in `Workbench.svelte`. +- Evidence: `tests/smoke/layout/keyboardFocus.smoke.mjs`. +- Replaces / replaced by: The radio rule of [UI-003](#ui-003--quiet-menu-choices). Other parts of UI-003 remain. +- Limits: The check mark replaces the icon of a radio row. The list of all tabs names pinned tabs in text. Browser checks use desktop service mocks. diff --git a/docs/ui-design.md b/docs/ui-design.md index 883ba5e..328aa78 100644 --- a/docs/ui-design.md +++ b/docs/ui-design.md @@ -70,6 +70,11 @@ Do not copy feature-specific colors into a shared control. - Controls, menu rows, and navigation highlights use `--rs-control-radius`. This includes hover, active, and selected states. - Keep readable labels, visible focus indicators, and comfortable click targets in compact layouts. +- Keyboard focus shows a 2-pixel `--rs-focus` ring outside the control. Menu rows draw the ring inside the row. Hover never shows the ring. +- Hover gets a neutral fill. An active toggle also gets the accent color, the selection fill, and a 2-pixel accent bar, so it differs from hover. +- A disabled control uses `--rs-text-dim` at full opacity. Do not fade a control with opacity. +- A composite widget, such as the file tree, has one Tab stop. The arrow keys move inside it. +- A splitter takes keyboard focus. The arrow keys move it by 16 pixels, and Home and End go to its limits. - Native form controls, such as checkboxes, take their accent from `--rs-accent`, not the browser default ([UI-030](design-decisions.md#ui-030--settings-installation-checkbox-theme-drift)). - Document tables are the exception. Keep their grid, cells, and cell selection outlines square. Table toolbars and table menus stay rounded. @@ -107,9 +112,9 @@ Use one menu design for context menus, action menus, and their submenus in the h - A common text action has the same label, icon, and shortcut in every menu. Build Undo, Redo, the clipboard rows, and the search row with `menuItems.ts`. - Write shortcut labels with `src/lib/ui/shortcuts.ts`: `keys("Mod+Shift+P")` gives Ctrl+Shift+P on Windows and Linux and ⇧⌘P on macOS. A workbench command takes its label from `commandShortcut()` in `workbenchKeys.ts`. Do not write "Ctrl" in interface text or in the catalog. Use a placeholder. - Use inset separators between related groups. -- Enabled rows share one hover fill and one keyboard focus fill. -- Disabled rows stay readable. Keyboard navigation skips them, and they do not run. -- Radio choices mark the current option with the shared fill and no checkmark. The current enabled radio choice gets focus when the menu opens. +- Enabled rows share one hover fill. Keyboard focus adds a 2-pixel ring inside the row. +- Disabled rows stay readable: dim text at full opacity. Keyboard navigation skips them, and they do not run. +- Radio choices mark the current option with a check mark in the icon column, and no fill. The current enabled radio choice gets focus when the menu opens. - A row can have a default action and a submenu. A click on the label, Enter, or Space runs the default action. Hover, the submenu arrow, or Right opens the submenu. ### Keyboard and viewport diff --git a/docs/user-guide.md b/docs/user-guide.md index 6878254..b7ebac5 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -50,6 +50,7 @@ To show workspace settings and plugin data in the navigator, turn on **Settings Right-click a file or folder for more actions, such as **Make a copy**, **Copy workspace path**, and **Open in default app**. With the navigator focused, Ctrl+X, Ctrl+C, and Ctrl+V cut, copy, and paste files. +The navigator is one Tab stop. Up and Down move between items, and Shift+Up or Shift+Down extends the selection. Right opens a folder or enters it. Left closes a folder or goes to its parent. Home and End go to the first and last item. Type the start of a name to go to it. Ctrl+Z undoes a file move or rename, and Ctrl+Shift+Z or Ctrl+Y repeats it. ### Delete files @@ -230,12 +231,14 @@ This table lists the Windows and Linux keys. On macOS, Cmd replaces Ctrl, and Ru | Switch Write and Source | Ctrl+E | | Switch Read and the editor | Ctrl+Shift+E | | Nest a list item / Move it up | Tab / Shift+Tab | +| Leave the text, then move the focus on | Esc, then Tab | | Bold / Italic / Link (Write) | Ctrl+B / Ctrl+I / Ctrl+K | | Strikethrough / Highlight (Write) | Ctrl+Shift+X / Ctrl+Shift+H | | Show or hide the sidebar | Ctrl+\ | | Rename | F2 | | Delete to the trash / Delete permanently | Delete / Shift+Delete | | Context menu | Shift+F10 | +| Resize a pane | Tab to its divider, then press the arrow keys | | Settings / Help and about | Ctrl+, / F1 | The [Terminal guide](guides/terminal.md) lists the terminal shortcuts. diff --git a/src/lib/editor/imageControls.css b/src/lib/editor/imageControls.css index 306beaa..00e3ae2 100644 --- a/src/lib/editor/imageControls.css +++ b/src/lib/editor/imageControls.css @@ -12,7 +12,7 @@ .image-action { position: relative; display: inline-grid; place-items: center; flex: 0 0 34px; width: 34px; height: 34px; padding: 6px; color: var(--rs-text); border: 0; border-radius: 4px; background: transparent; cursor: pointer; } .image-action:hover, .image-action:focus-visible { background: var(--rs-bg-active); color: var(--rs-text-strong); } .image-action:focus-visible { outline: 2px solid var(--rs-focus); outline-offset: 1px; } -.image-action:disabled { opacity: .4; cursor: default; } +.image-action:disabled { color: var(--rs-text-dim); cursor: default; } .image-lightbox { position: fixed; inset: 0; width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: var(--rs-image-viewer-bg); color: var(--rs-text); } .image-lightbox[open] { display: flex; flex-direction: column; } .image-lightbox::backdrop { background: var(--rs-scrim); } diff --git a/src/lib/i18n/messages.ts b/src/lib/i18n/messages.ts index 3461411..e26a25a 100644 --- a/src/lib/i18n/messages.ts +++ b/src/lib/i18n/messages.ts @@ -3461,6 +3461,11 @@ export const messageRows: [string, string, string, string][] = [ ["Unsaved", "Non enregistré", "未保存", "未保存"], ["All tabs", "Tous les onglets", "すべてのタブ", "所有标签页"], ["Open folder ({shortcut})", "Ouvrir un dossier ({shortcut})", "フォルダーを開く ({shortcut})", "打开文件夹 ({shortcut})"], + ["Pinned", "Épinglé", "ピン留め", "已固定"], + ["Resize the side pane", "Redimensionner le panneau latéral", "サイドパネルのサイズを変更", "调整侧边面板大小"], + ["Resize the outline", "Redimensionner le plan", "アウトラインのサイズを変更", "调整大纲大小"], + ["Resize the terminal", "Redimensionner le terminal", "ターミナルのサイズを変更", "调整终端大小"], + ["Leave the text, then press Tab", "Quitter le texte, puis appuyer sur Tab", "テキストから出て、Tab キーを押す", "离开文本,然后按 Tab"], ]; export const catalogs: Record, Record> = { fr: Object.fromEntries(messageRows.map(row => [row[0], row[1]])), diff --git a/src/lib/layout/FileTree.svelte b/src/lib/layout/FileTree.svelte index f887a1f..2c4189b 100644 --- a/src/lib/layout/FileTree.svelte +++ b/src/lib/layout/FileTree.svelte @@ -217,6 +217,56 @@ selection = { paths: new Set([rel]), anchor: rel }; } + // The tree has one Tab stop: the last focused row, else the selection, the open file, or the first row. + let focusRel = $state(null); + const tabStop = $derived([focusRel, selection.anchor, activePath].find(path => path && visiblePaths.includes(path)) ?? visiblePaths[0] ?? null); + let typed = "", typedAt = 0; + + async function focusRow(rel: string) { + focusRel = rel; + await tick(); + const row = [...treeElement.querySelectorAll("[data-tree-rel]")].find(node => node.dataset.treeRel === rel); + row?.focus({ preventScroll: true }); + row?.scrollIntoView({ block: "nearest" }); + } + + // The keys of the tree pattern: arrows move, Right opens or enters a folder, Left closes it or goes to its parent, + // Home and End go to the ends, and typed letters find a row. Shift with an arrow extends the selection. + function treeKey(event: KeyboardEvent) { + const row = event.target instanceof HTMLElement && event.target.matches("[data-tree-rel]") ? event.target : null; + if (!row || event.ctrlKey || event.metaKey || event.altKey) return; + const rel = row.dataset.treeRel!; + const entry = findEntry(rel); + const index = visiblePaths.indexOf(rel); + if (!entry || index < 0) return; + let next: string | undefined; + if (event.key === "ArrowDown") next = visiblePaths[index + 1]; + else if (event.key === "ArrowUp") next = visiblePaths[index - 1]; + else if (event.key === "Home") next = visiblePaths[0]; + else if (event.key === "End") next = visiblePaths.at(-1); + else if (event.key === "ArrowRight") { + if (entry.kind !== "folder") return; + event.preventDefault(); + if (!expanded.has(rel)) toggleFolder(entry); + else if (childrenMap[rel]?.length) next = childrenMap[rel][0].rel_path; + } else if (event.key === "ArrowLeft") { + event.preventDefault(); + if (entry.kind === "folder" && expanded.has(rel)) toggleFolder(entry); + else if (rel.includes("/")) next = parentRel(rel); + } else if (event.key.length === 1 && event.key !== " ") { + const now = Date.now(); + typed = (now - typedAt < 700 ? typed : "") + event.key.toLowerCase(); + typedAt = now; + const order = [...visiblePaths.slice(index + (typed.length === 1 ? 1 : 0)), ...visiblePaths.slice(0, index + (typed.length === 1 ? 1 : 0))]; + next = order.find(path => (path.split("/").pop() ?? path).toLowerCase().startsWith(typed)); + if (!next) return; + } else return; + event.preventDefault(); + if (!next) return; + selection = event.shiftKey && event.key.startsWith("Arrow") ? selectTreePath(selection, next, visiblePaths, { shiftKey: true }) : { paths: new Set([next]), anchor: next }; + void focusRow(next); + } + function onRowClick(entry: TreeEntry, modifiers: SelectionModifiers = {}, newTab = false) { if (skipClick) { skipClick = false; @@ -945,7 +995,8 @@

{$t("Loading…")}

{/if} {#if childrenMap[""]} -
    + +
      {#each childrenMap[""] as entry (entry.rel_path)} void commitRename()} onRenameCancel={cancelRename} {onDragPointerDown} + {tabStop} + onFocusRow={(rel) => (focusRel = rel)} /> {/each}
    diff --git a/src/lib/layout/SettingsDialog.svelte b/src/lib/layout/SettingsDialog.svelte index 079d857..1397cd3 100644 --- a/src/lib/layout/SettingsDialog.svelte +++ b/src/lib/layout/SettingsDialog.svelte @@ -235,7 +235,7 @@ .switch:checked::before { transform: translateX(16px); background: var(--rs-bg); } .interval { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; font-size: 11px; color: var(--rs-text-dim); } .interval input { width: 72px; min-height: var(--rs-settings-control-height); padding: 4px 6px; border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); background: var(--rs-bg); color: var(--rs-text); font-size: 13px; } - .interval input:disabled { opacity: .45; } + .interval input:disabled { color: var(--rs-text-dim); } .note, .section-footer, .about-note { font-size: 12px; } .note { margin: 10px 0 var(--rs-settings-section-gap); } .section-footer { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; color: var(--rs-text-dim); } diff --git a/src/lib/layout/TabBar.svelte b/src/lib/layout/TabBar.svelte index c80544d..0958323 100644 --- a/src/lib/layout/TabBar.svelte +++ b/src/lib/layout/TabBar.svelte @@ -176,8 +176,8 @@ menuAnchor = allTabsButton; const bounds = allTabsButton!.getBoundingClientRect(); menu = actionMenu(bounds.left, bounds.bottom + 2, tabs.map(tab => ({ - label: tab.name, radio: true, checked: tab.relPath === activePath, icon: tab.pinned ? "pin" as const : undefined, - shortcut: tab.dirty ? $t("Unsaved") : undefined, + label: tab.name, radio: true, checked: tab.relPath === activePath, + shortcut: [tab.pinned ? $t("Pinned") : "", tab.dirty ? $t("Unsaved") : ""].filter(Boolean).join(" · ") || undefined, // As with a click on the tab, the workbench then focuses the document. run: () => { closeMenu(); onSelect(tab.relPath); }, })), () => closeMenu(true), $t("All tabs")); diff --git a/src/lib/layout/TreeNode.svelte b/src/lib/layout/TreeNode.svelte index 90ce325..325df67 100644 --- a/src/lib/layout/TreeNode.svelte +++ b/src/lib/layout/TreeNode.svelte @@ -28,6 +28,9 @@ dropTarget: DropTarget | null; dragRel: string | null; onDragPointerDown: (entry: TreeEntry, event: PointerEvent) => void; + /** The row with the only Tab stop of the tree. */ + tabStop: string | null; + onFocusRow: (rel: string) => void; }; let { @@ -49,6 +52,8 @@ dropTarget, dragRel, onDragPointerDown, + tabStop, + onFocusRow, }: Props = $props(); let isOpen = $derived(expanded.has(entry.rel_path)); @@ -93,7 +98,7 @@ data-tree-rel={entry.rel_path} data-tree-kind={entry.kind} role="treeitem" - tabindex="0" + tabindex={entry.rel_path === tabStop ? 0 : -1} aria-selected={isSelected} aria-expanded={entry.kind === "folder" ? isOpen : undefined} aria-level={entry.rel_path.split("/").length} @@ -102,6 +107,7 @@ onDragPointerDown(entry, event); }} onclick={(event) => onRowClick(entry, event)} + onfocus={(event) => { if (event.target === event.currentTarget) onFocusRow(entry.rel_path); }} onauxclick={(event) => { if (event.button !== 1) return; event.preventDefault(); @@ -184,6 +190,8 @@ {dropTarget} {dragRel} {onDragPointerDown} + {tabStop} + {onFocusRow} /> {/each}
diff --git a/src/lib/layout/Workbench.svelte b/src/lib/layout/Workbench.svelte index b4bdf5e..d918786 100644 --- a/src/lib/layout/Workbench.svelte +++ b/src/lib/layout/Workbench.svelte @@ -1104,6 +1104,18 @@ } } + // A splitter takes keyboard focus. The arrow keys move it by 16 pixels, and Home and End go to its limits. + function splitterKey(event: KeyboardEvent, pane: "left" | "right" | "bottom") { + const steps: Record = pane === "bottom" ? { ArrowUp: 16, ArrowDown: -16 } : pane === "left" ? { ArrowRight: 16, ArrowLeft: -16 } : { ArrowLeft: 16, ArrowRight: -16 }; + const [min, max] = pane === "bottom" ? [80, Math.max(80, (centerStack?.getBoundingClientRect().height ?? 400) - 80)] : [160, 480]; + const current = pane === "left" ? leftWidth : pane === "right" ? rightWidth : bottomHeight; + const next = event.key === "Home" ? min : event.key === "End" ? max : event.key in steps ? current + steps[event.key] : null; + if (next === null) return; + event.preventDefault(); + const value = Math.min(max, Math.max(min, next)); + if (pane === "left") leftWidth = value; else if (pane === "right") rightWidth = value; else bottomHeight = value; + } + function updateSettings(next: AppSettings) { const saved = saveSettings(next); settings = { ...next }; @@ -1266,10 +1278,18 @@ onStatus={(message) => { status = message; error = null; }} /> + {/if} @@ -1310,10 +1330,17 @@ onOpenLink={(pane, kind, target) => void openLink(kind, target, pane.buffer?.relPath ?? "", pane.id)} /> {#if terminalContribution && terminalStarted} +
{#if workspace} @@ -1331,10 +1358,18 @@ {#if rightOpen && !transferredWindow} + void; children?: ActionMenuItem[]; disabled?: boolean; checked?: boolean; radio?: boolean; title?: string } | { separator: true }; export function actionMenu(x: number, y: number, items: ActionMenuItem[], onClose: () => void, label = "Table actions", parent: HTMLElement = document.body) { @@ -32,7 +39,7 @@ export function actionMenu(x: number, y: number, items: ActionMenuItem[], onClos if (focus) focusRow(panel.querySelector("button:not(:disabled)") ?? undefined); } function populate(panel: HTMLElement, entries: ActionMenuItem[]) { - const hasIcons = entries.some(item => !("separator" in item) && (!!item.icon || (item.checked !== undefined && !item.radio))); + const hasIcons = entries.some(item => !("separator" in item) && (!!item.icon || item.checked !== undefined)); panel.classList.toggle("rs-menu-text", !hasIcons); for (const item of entries) { if ("separator" in item) { const hr = document.createElement("hr"); hr.setAttribute("role", "separator"); panel.append(hr); continue; } @@ -40,7 +47,8 @@ export function actionMenu(x: number, y: number, items: ActionMenuItem[], onClos if (item.checked !== undefined) { button.setAttribute("role", item.radio ? "menuitemradio" : "menuitemcheckbox"); button.setAttribute("aria-checked", String(item.checked)); } if (item.title) button.title = item.title; const label = document.createElement("span"); label.className = "action-label"; label.textContent = item.label; - const icon = item.checked && !item.radio ? actionIcon("task") : item.icon ? actionIcon(item.icon) : document.createElement("span"); + const icon = item.radio ? (item.checked ? checkMark() : document.createElement("span")) + : item.checked ? actionIcon("task") : item.icon ? actionIcon(item.icon) : document.createElement("span"); icon.classList.add("action-icon"); icon.setAttribute("aria-hidden", "true"); button.append(icon, label); panel.append(button); if (item.shortcut) { const shortcut = document.createElement("span"); shortcut.textContent = item.shortcut; shortcut.style.cssText = "margin-left:auto;color:var(--rs-text-dim);font-size:12px;white-space:nowrap"; button.append(shortcut); } diff --git a/src/lib/ui/menu.css b/src/lib/ui/menu.css index 07eb831..d2c627a 100644 --- a/src/lib/ui/menu.css +++ b/src/lib/ui/menu.css @@ -35,14 +35,20 @@ cursor: pointer; } -.rs-menu > button:disabled, .rs-picker .rs-picker-row:disabled { opacity: .4; cursor: default; } -.rs-menu > button[role="menuitemradio"][aria-checked="true"] { background: var(--rs-menu-active-bg); } +/* Disabled rows stay readable: dim text at full opacity. */ +.rs-menu > button:disabled, .rs-picker .rs-picker-row:disabled { color: var(--rs-text-dim); cursor: default; } .rs-menu.rs-menu-text > button > .action-icon { display: none; } +/* Hover gets only the quiet fill. The current radio row shows a check mark, not a fill. */ .rs-menu > button:not(:disabled):is(:hover, :focus-visible, [aria-expanded="true"]), .rs-picker .rs-picker-row:not(:disabled):is(:hover, :focus-visible, :focus-within, [aria-selected="true"], [aria-current="true"]) { background: var(--rs-menu-active-bg); outline: none; } +/* Keyboard focus also gets a 2-pixel ring, so it differs from hover. */ +.rs-menu > button:not(:disabled):focus-visible, .rs-picker .rs-picker-row:not(:disabled):focus-visible { + outline: 2px solid var(--rs-focus); + outline-offset: -2px; +} .rs-menu > hr { margin: 4px 0; border: 0; border-top: 1px solid var(--rs-border); } .rs-menu > button > .action-icon, .rs-picker-icon { width: var(--rs-menu-icon-size); height: var(--rs-menu-icon-size); flex: 0 0 var(--rs-menu-icon-size); } .rs-picker-hint { display: block; color: var(--rs-text-dim); font-size: var(--rs-settings-description-size); } diff --git a/tests/smoke/appearance/backgroundImages.smoke.mjs b/tests/smoke/appearance/backgroundImages.smoke.mjs index 73d7824..8559019 100644 --- a/tests/smoke/appearance/backgroundImages.smoke.mjs +++ b/tests/smoke/appearance/backgroundImages.smoke.mjs @@ -89,7 +89,8 @@ await runSmoke('appearance/backgroundImages', async ({ browser }) => { assert.equal(await menu.evaluate(node => getComputedStyle(node).fontSize), '13px'); // Shared menu rows are 24px high (src/lib/theme/tokens.css:31, --rs-menu-row-height). assert.equal(await menu.locator(':scope > button').first().evaluate(node => getComputedStyle(node).minHeight), '24px'); - assert.equal(await menu.locator('[aria-checked="true"] svg').count(), 0); + // The current choice shows a check mark in the icon column (src/lib/ui/actionMenu.ts). + assert.equal(await menu.locator('[aria-checked="true"] svg').count(), 1); assert.equal(await menu.evaluate(node => { const reference = document.createElement('span'); reference.style.color = 'var(--rs-menu-border)'; node.append(reference); const matches = getComputedStyle(node).borderColor === getComputedStyle(reference).color; reference.remove(); return matches; }), true, 'Menu uses the shared border token'); assert.equal(await menu.evaluate(node => getComputedStyle(node).borderColor), 'rgba(0, 0, 0, 0)', 'Menus have no visible border'); await settings.screenshot({ path: `${output}/${name.replaceAll(' ', '-')}-${mode}.png` }); diff --git a/tests/smoke/layout/keyboardFocus.smoke.mjs b/tests/smoke/layout/keyboardFocus.smoke.mjs new file mode 100644 index 0000000..6657523 --- /dev/null +++ b/tests/smoke/layout/keyboardFocus.smoke.mjs @@ -0,0 +1,148 @@ +// Keyboard and focus: radio check marks, menu focus rings, hover against active, readable disabled controls, the file tree keys, and splitters. +import assert from "node:assert/strict"; +import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs"; + +await runSmoke("layout/keyboardFocus", async ({ page }) => { + const output = await outputDir("layout/keyboardFocus"); + await mockTauri(page, { + commands: test => ({ + ...test.workspace({ + root: "C:\\keyboard", + files: { + "alpha.md": "# Alpha\n", + "beta.md": "# Beta\n", + "notes/first.md": "# First\n", + "notes/second.md": "# Second\n", + "notes/deep/third.md": "# Third\n", + "zeta.txt": "Zeta\n", + }, + }), + plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }), + "plugin:window|is_maximized": () => false, + }), + }); + await page.setViewportSize({ width: 1280, height: 760 }); + await page.goto(smokeUrl); + const tree = page.getByRole("tree", { name: "Workspace files" }); + const row = rel => page.locator(`[data-tree-rel="${rel}"]`); + const focused = () => page.evaluate(() => document.activeElement?.getAttribute("data-tree-rel") ?? document.activeElement?.getAttribute("aria-label")); + await row("alpha.md").waitFor(); + + // The tree has one Tab stop. Arrow keys move, Right opens or enters a folder, Left closes it or goes up. + assert.equal(await tree.locator('[role="treeitem"][tabindex="0"]').count(), 1); + await row("alpha.md").click(); + await page.getByRole("tab", { name: "alpha.md", exact: true, selected: true }).waitFor(); + await row("alpha.md").focus(); + await page.keyboard.press("ArrowDown"); + assert.equal(await focused(), "beta.md"); + assert.equal(await row("beta.md").getAttribute("aria-selected"), "true"); + // Folders come first: notes, alpha.md, beta.md, zeta.txt. + await page.keyboard.press("ArrowDown"); + assert.equal(await focused(), "zeta.txt"); + await page.keyboard.press("Home"); + assert.equal(await focused(), "notes"); + await page.keyboard.press("ArrowRight"); + await row("notes/first.md").waitFor(); + assert.equal(await row("notes").getAttribute("aria-expanded"), "true"); + await page.keyboard.press("ArrowRight"); + assert.equal(await focused(), "notes/deep"); + await page.keyboard.press("ArrowLeft"); + assert.equal(await focused(), "notes"); + await page.keyboard.press("ArrowLeft"); + assert.equal(await row("notes").getAttribute("aria-expanded"), "false"); + await page.keyboard.press("End"); + assert.equal(await focused(), "zeta.txt"); + await page.keyboard.press("Home"); + assert.equal(await focused(), "notes"); + await page.keyboard.press("z"); + assert.equal(await focused(), "zeta.txt"); + await page.keyboard.press("Shift+ArrowUp"); + assert.equal(await tree.locator('[aria-selected="true"]').count(), 2); + assert.equal(await tree.locator('[role="treeitem"][tabindex="0"]').count(), 1); + // Tab leaves the tree at once. + await page.keyboard.press("Tab"); + assert.notEqual(await page.evaluate(() => !!document.activeElement?.closest('[role="tree"]')), true); + await page.keyboard.press("Shift+Tab"); + assert.equal(await page.evaluate(() => !!document.activeElement?.closest('[role="tree"]')), true); + + // A splitter takes focus. The arrow keys move it by 16 pixels, and Home and End go to its limits. + const splitter = page.getByRole("separator", { name: "Resize the side pane", exact: true }); + const width = () => page.locator("aside.left").evaluate(node => Math.round(node.getBoundingClientRect().width)); + const before = await width(); + await splitter.focus(); + await page.keyboard.press("ArrowRight"); + assert.equal(await width(), before + 16); + assert.equal(await splitter.getAttribute("aria-valuenow"), String(before + 16)); + await page.keyboard.press("Home"); + assert.equal(await width(), 160); + await page.keyboard.press("End"); + assert.equal(await width(), 480); + assert.equal(await splitter.evaluate(node => getComputedStyle(node).outlineWidth), "2px"); + const outline = page.getByRole("separator", { name: "Resize the outline", exact: true }); + await outline.focus(); + const right = () => page.locator("aside.right").evaluate(node => Math.round(node.getBoundingClientRect().width)); + const rightBefore = await right(); + await page.keyboard.press("ArrowLeft"); + assert.equal(await right(), rightBefore + 16); + await splitter.focus(); + await page.keyboard.press("Home"); + + for (const theme of ["dark", "light"]) { + await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); window.dispatchEvent(new Event("focus")); }, theme); + await page.waitForFunction(mode => document.documentElement.dataset.theme === mode, theme); + + // An active toggle differs from a hovered button. A disabled button keeps full opacity and dim text. + const files = page.getByRole("button", { name: "Files", exact: true }); + const search = page.getByRole("button", { name: "Search", exact: true }); + await search.hover(); + const look = locator => locator.evaluate(node => { const style = getComputedStyle(node); return { fill: style.backgroundColor, color: style.color, bar: style.boxShadow }; }); + const [hovered, active] = [await look(search), await look(files)]; + assert.equal(hovered.bar, "none"); + assert.match(active.bar, /inset/); + assert.notEqual(hovered.color, active.color); + const save = page.getByRole("button", { name: "Save", exact: true }); + assert.equal(await save.isDisabled(), true); + assert.equal(await save.evaluate(node => getComputedStyle(node).opacity), "1"); + const dim = await page.evaluate(() => { const probe = document.createElement("span"); probe.style.color = "var(--rs-text-dim)"; document.body.append(probe); const color = getComputedStyle(probe).color; probe.remove(); return color; }); + assert.equal(await save.evaluate(node => getComputedStyle(node).color), dim); + await page.locator("header.header").screenshot({ path: `${output}/header-states-${theme}.png` }); + + // The current radio row shows a check mark and no fill. Keyboard focus adds a ring that hover does not have. + await page.getByRole("tab", { name: "alpha.md", exact: true }).click({ button: "right" }); + await page.getByRole("menuitem", { name: "View", exact: true }).click(); + const write = page.getByRole("menuitemradio", { name: "Write", exact: true }); + const source = page.getByRole("menuitemradio", { name: "Source", exact: true }); + assert.equal(await write.getAttribute("aria-checked"), "true"); + assert.equal(await write.locator("svg").count(), 1); + assert.equal(await source.locator("svg").count(), 0); + await source.hover(); + assert.equal(await source.evaluate(node => getComputedStyle(node).outlineStyle), "none"); + await write.focus(); + await page.keyboard.press("ArrowDown"); + const keyed = page.locator('[role="menu"] button:focus-visible'); + assert.equal(await keyed.getAttribute("aria-checked"), "false"); + assert.equal(await keyed.evaluate(node => getComputedStyle(node).outlineWidth), "2px"); + // With focus and the pointer on other rows, the checked row has no fill. + await page.mouse.move(0, 700); + assert.equal(await write.evaluate(node => getComputedStyle(node).backgroundColor), "rgba(0, 0, 0, 0)"); + await page.screenshot({ path: `${output}/menu-check-${theme}.png` }); + await page.keyboard.press("Escape"); + await page.keyboard.press("Escape"); + await page.keyboard.press("Escape"); + + // Disabled menu rows keep full opacity and dim text. + await page.getByRole("tab", { name: "alpha.md", exact: true }).click({ button: "right" }); + const disabled = page.getByRole("menuitem", { name: "Close tabs after", exact: true }); + assert.equal(await disabled.isDisabled(), true); + assert.equal(await disabled.evaluate(node => getComputedStyle(node).opacity), "1"); + assert.equal(await disabled.evaluate(node => getComputedStyle(node).color), dim); + await page.keyboard.press("Escape"); + } + + // Help names the key that leaves the text before Tab moves on. + await page.keyboard.press("F1"); + await page.getByRole("dialog", { name: "Help and about" }).getByText("Leave the text, then press Tab", { exact: true }).waitFor(); + await page.getByRole("button", { name: "Close help", exact: true }).click(); + assert.deepEqual(page.errors, []); + console.log("PASS: one tree Tab stop, tree keys, type-ahead, range selection, keyboard splitters, radio check marks, menu focus ring, hover against active, readable disabled controls, Help, both themes."); +});