Show the current choice, keyboard focus, and states apart

Phase 5-5.

- The current radio row shows a check mark in the icon column and no
  fill (UI-051, replaces the radio rule of UI-003). The list of all
  tabs names pinned tabs in text.
- Keyboard focus adds a 2-pixel ring inside menu rows. The global
  focus ring is 2 pixels with a 1-pixel offset.
- Active toggles get the accent color, the selection fill, and a
  2-pixel accent bar. Hover gets only a neutral fill. Enabled icon
  buttons use --rs-text.
- Disabled controls use --rs-text-dim at full opacity, not opacity.
- The file tree has one Tab stop. Up and Down move, Shift extends the
  selection, 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.
- The three workbench splitters take focus. The arrow keys move them
  by 16 pixels, and Home and End go to their limits.
- Help names Esc, then Tab, to leave the text.
- 5 new catalog rows in French, Japanese, and Simplified Chinese.
- Docs: UI-051, ui-design.md, and the user guide.

Tests: the new layout/keyboardFocus. backgroundImages now expects the
check mark on the current radio row.
This commit is contained in:
Knotty Wyvern
2026-10-28 20:44:35 -07:00
parent c8cf56b224
commit b7a9784f55
19 changed files with 322 additions and 23 deletions
+1 -1
View File
@@ -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); }
+5
View File
@@ -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<Exclude<Locale, 'en'>, Record<string, string>> = {
fr: Object.fromEntries(messageRows.map(row => [row[0], row[1]])),
+54 -1
View File
@@ -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<string | null>(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<HTMLElement>("[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 @@
<p class="muted">{$t("Loading…")}</p>
{/if}
{#if childrenMap[""]}
<ul role="tree" aria-label={$t("Workspace files")} aria-multiselectable="true">
<!-- svelte-ignore a11y_no_noninteractive_element_interactions (The tree handles the keys of its rows.) -->
<ul role="tree" aria-label={$t("Workspace files")} aria-multiselectable="true" onkeydown={treeKey}>
{#each childrenMap[""] as entry (entry.rel_path)}
<TreeNode
{entry}
@@ -969,6 +1020,8 @@
onRenameCommit={() => void commitRename()}
onRenameCancel={cancelRename}
{onDragPointerDown}
{tabStop}
onFocusRow={(rel) => (focusRel = rel)}
/>
{/each}
</ul>
+1 -1
View File
@@ -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); }
+2 -2
View File
@@ -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"));
+9 -1
View File
@@ -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}
</ul>
+35
View File
@@ -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<string, number> = 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; }}
/>
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions (A focusable separator is the splitter pattern.) -->
<div
class="gutter gutter-v"
role="separator"
tabindex="0"
aria-orientation="vertical"
aria-label={$t("Resize the side pane")}
aria-valuenow={leftWidth}
aria-valuemin={160}
aria-valuemax={480}
onpointerdown={() => (dragging = "left")}
onkeydown={(event) => splitterKey(event, "left")}
></div>
{/if}
@@ -1310,10 +1330,17 @@
onOpenLink={(pane, kind, target) => void openLink(kind, target, pane.buffer?.relPath ?? "", pane.id)}
/>
{#if terminalContribution && terminalStarted}
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions (A focusable separator is the splitter pattern.) -->
<div
class="gutter gutter-h" class:terminal-hidden={!terminalOpen}
role="separator"
tabindex="0"
aria-orientation="horizontal"
aria-label={$t("Resize the terminal")}
aria-valuenow={bottomHeight}
aria-valuemin={80}
onpointerdown={() => (dragging = "bottom")}
onkeydown={(event) => splitterKey(event, "bottom")}
></div>
<section class="bottom" class:terminal-hidden={!terminalOpen}>
{#if workspace}
@@ -1331,10 +1358,18 @@
</div>
{#if rightOpen && !transferredWindow}
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions (A focusable separator is the splitter pattern.) -->
<div
class="gutter gutter-v"
role="separator"
tabindex="0"
aria-orientation="vertical"
aria-label={$t("Resize the outline")}
aria-valuenow={rightWidth}
aria-valuemin={160}
aria-valuemax={480}
onpointerdown={() => (dragging = "right")}
onkeydown={(event) => splitterKey(event, "right")}
></div>
<RightPane
{outlineItems}
+1 -1
View File
@@ -164,7 +164,7 @@
form button { display: flex; align-items: center; gap: 10px; background: transparent; border: 1px solid transparent; border-radius: var(--rs-control-radius); padding: 9px 10px; color: var(--rs-text); text-align: left; }
form button:hover { background: var(--rs-bg-active); }
form button:focus-visible, input:focus-visible { outline: 2px solid var(--rs-focus); outline-offset: -2px; }
form button:disabled { opacity: .5; }
form button:disabled { color: var(--rs-text-dim); }
.workspace-row, footer button { width: 100%; }
.workspace-entry { display: flex; align-items: stretch; }
.workspace-entry .workspace-row { flex: 1; min-width: 0; }
+2
View File
@@ -84,6 +84,8 @@ export const OTHER_SHORTCUTS: readonly { section: string; label: string; keys: s
{ section: message("Write"), label: message("Strikethrough"), keys: "Mod+Shift+X" },
{ section: message("Write"), label: message("Highlight"), keys: "Mod+Shift+H" },
{ section: message("Write"), label: message("Find in the document"), keys: "Mod+F" },
// Tab indents in the editor. Escape first leaves the text, so the next Tab moves the focus on.
{ section: message("Write"), label: message("Leave the text, then press Tab"), keys: "Escape" },
{ section: message("Files"), label: message("Rename"), keys: "F2" },
{ section: message("Files"), label: message("Move to the Recycle Bin"), keys: "Delete", macKeys: "Mod+Backspace" },
{ section: message("Files"), label: message("Delete permanently"), keys: "Shift+Delete", macKeys: "Mod+Alt+Backspace" },
+1 -1
View File
@@ -202,7 +202,7 @@
p { margin: 6px 0 10px; color: var(--rs-text-dim); line-height: 1.45; }
button { display: inline-flex; align-items: center; justify-content: center; gap: var(--rs-settings-gap); min-height: var(--rs-settings-control-height); padding: 4px 8px; color: var(--rs-text); background: var(--rs-bg-elevated); border: 1px solid var(--rs-border); border-radius: var(--rs-control-radius); }
button:hover:not(:disabled) { background: var(--rs-bg-active); }
button:disabled { opacity: .5; }
button:disabled { color: var(--rs-text-dim); }
.toolbar, footer { display: flex; align-items: center; flex-wrap: wrap; gap: var(--rs-settings-gap); }
.card { border-bottom: 1px solid var(--rs-border); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: var(--rs-settings-row-padding) 0; }
+5 -3
View File
@@ -34,14 +34,16 @@ button {
cursor: pointer;
}
/* A disabled control uses dim text at full opacity, so it stays readable. */
button:disabled {
cursor: default;
opacity: 0.5;
color: var(--rs-text-dim);
}
/* Keyboard focus: a 2-pixel ring outside the control. */
:focus-visible {
outline: 1px solid var(--rs-focus);
outline-offset: -1px;
outline: 2px solid var(--rs-focus);
outline-offset: 1px;
}
::selection {
+12 -4
View File
@@ -127,19 +127,27 @@
padding: 0;
border: 1px solid transparent;
background: transparent;
color: var(--rs-text-dim);
color: var(--rs-text);
display: inline-flex;
align-items: center;
justify-content: center;
}
.icon-btn:hover,
.icon-btn.active {
/* Hover gets a neutral fill. An active toggle also gets the accent color and an accent bar. A disabled button is dim. */
.icon-btn:not(:disabled):hover {
background: var(--rs-bg-active);
border-color: var(--rs-border);
color: var(--rs-accent);
color: var(--rs-text-strong);
}
.icon-btn.active {
background: var(--rs-item-selection-bg);
color: var(--rs-accent);
box-shadow: inset 0 -2px 0 var(--rs-accent);
}
.icon-btn:disabled { color: var(--rs-text-dim); }
.tip {
position: fixed;
inset: auto;
+10 -2
View File
@@ -1,5 +1,12 @@
import { actionIcon, type ActionIcon } from "./actionIcons.ts";
/** The check mark of the current radio row. It sits in the icon column and replaces the icon of the row. */
function checkMark() {
const svg = actionIcon("task");
svg.innerHTML = '<path d="M5 12.5 9.5 17 19 7"/>';
return svg;
}
export type ActionMenuItem = { label: string; icon?: ActionIcon; shortcut?: string; run?: () => 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<HTMLButtonElement>("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); }
+8 -2
View File
@@ -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); }