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:
@@ -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>
|
||||
|
||||
@@ -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); }
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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" },
|
||||
|
||||
Reference in New Issue
Block a user