Show one view control and name the file once

Phase 5-3.

- One radio group shows Write, Source, and Read at all times, with an
  icon and a name. Narrow panes show only the icons. The arrow keys
  move the choice, and the group has one Tab stop. The current choice
  gets the selection fill and an accent bar. Hover gets only a fill.
- A Split toggle shows Read beside Write or Source. Each document pane
  keeps a split flag beside its reading flag. Read ends Split.
- Ctrl+Shift+E switches between Read and the editor. Ctrl+E still
  switches between Write and Source.
- "IDE" becomes "Source" in the Chrome type, the tab menu (a View
  submenu), the status bar, the catalog, the tests, and the docs.
- Settings, General, File name title hides the title in Write and
  Read. It is on by default.
- The breadcrumb shows only the folder of the file. The status bar
  shows the view, not the path.
- ModeSwitcher.svelte and its hover test are gone. The new test
  layout/viewModes covers the control.
- The command palette from 5-2 gets its row in docs/menu-surfaces.json.
- The user guide Format table is whole again. The 5-2 edit had put
  the Paragraph and Insert rows under the shortcut table.
- 8 new catalog rows and 10 removed rows, in French, Japanese, and
  Simplified Chinese.
- Docs: UI-049, the user guide, ui-design.md, document-tools.md,
  development.md, and the README feature list.

Tests: the new layout/viewModes, new cases in documentPanes.spec.ts
and settings.spec.ts, and the chooseView harness helper. 21 smoke
tests use the new control. Tests that read the full path from the
breadcrumb now read its tooltip.
This commit is contained in:
Knotty Wyvern
2026-10-28 19:45:08 -07:00
parent ebacdb8164
commit 9cf82503d0
64 changed files with 675 additions and 590 deletions
+110
View File
@@ -0,0 +1,110 @@
<script lang="ts" module>
/** The view of a document pane. Split is a separate toggle beside Write or Source. */
export type ViewMode = "write" | "source" | "read";
</script>
<script lang="ts">
// The view control of a document pane: Write, Source, and Read in one radio group, then the Split toggle.
// All choices stay visible. Narrow panes show only the icons.
import { t } from "$lib/i18n";
import Icon from "$lib/ui/Icon.svelte";
import type { IconName } from "$lib/ui/IconButton.svelte";
import { attachTooltip } from "$lib/ui/tooltip";
import { commandShortcut } from "./workbenchKeys";
type Option = { value: ViewMode; label: string; icon: IconName; shortcut: string };
type Props = {
view: ViewMode;
split: boolean;
/** Markdown files have Read and Split. Other text files have only Write and Source. */
readable: boolean;
onView: (view: ViewMode) => void;
onSplit: (split: boolean) => void;
};
let { view, split, readable, onView, onSplit }: Props = $props();
let group: HTMLDivElement;
const options: Option[] = $derived([
{ value: "write", label: $t("Write"), icon: "pen", shortcut: commandShortcut("toggle-layout") },
{ value: "source", label: $t("Source"), icon: "code", shortcut: commandShortcut("toggle-layout") },
...(readable ? [{ value: "read" as const, label: $t("Read"), icon: "book-open" as const, shortcut: commandShortcut("toggle-reading") }] : []),
]);
function tooltip(node: HTMLElement, text: string) {
let current = text;
const dispose = attachTooltip(node, () => current);
return { update(value: string) { current = value; }, destroy: dispose };
}
// Arrow keys move the choice, as in each radio group. The group has one Tab stop.
function keydown(event: KeyboardEvent, index: number) {
const last = options.length - 1;
const next = event.key === "ArrowRight" || event.key === "ArrowDown" ? (index + 1) % options.length
: event.key === "ArrowLeft" || event.key === "ArrowUp" ? (index + last) % options.length
: event.key === "Home" ? 0 : event.key === "End" ? last : -1;
if (next < 0) return;
event.preventDefault();
onView(options[next].value);
group.querySelectorAll<HTMLButtonElement>("[role=radio]")[next]?.focus();
}
</script>
<div class="view-modes" role="radiogroup" aria-label={$t("View")} bind:this={group}>
{#each options as option, index (option.value)}
<button type="button" role="radio" aria-checked={option.value === view} aria-label={option.label}
tabindex={option.value === view ? 0 : -1}
use:tooltip={`${option.label} (${option.shortcut})`}
onclick={() => onView(option.value)} onkeydown={event => keydown(event, index)}>
<Icon icon={option.icon} /><span class="label" aria-hidden="true">{option.label}</span>
</button>
{/each}
</div>
{#if readable}
<button type="button" class="split" aria-pressed={split} aria-label={$t("Split")} use:tooltip={$t("Split: Read beside the editor")} onclick={() => onSplit(!split)}>
<Icon icon="split" /><span class="label" aria-hidden="true">{$t("Split")}</span>
</button>
{/if}
<style>
.view-modes {
display: inline-flex;
flex: 0 0 auto;
gap: 2px;
padding: 2px;
border: 1px solid var(--rs-border);
border-radius: var(--rs-control-radius);
}
button {
display: inline-flex;
flex: 0 0 auto;
align-items: center;
gap: 6px;
height: 26px;
min-width: 28px;
padding: 0 8px;
border: 0;
border-radius: var(--rs-control-radius);
background: transparent;
color: var(--rs-text-dim);
font: 12px var(--rs-font-ui);
white-space: nowrap;
}
button :global(svg) { width: 16px; height: 16px; flex-shrink: 0; }
/* Hover gets only a fill. The current choice also gets the selection fill and an accent bar. */
button:hover { background: var(--rs-bg-active); color: var(--rs-text-strong); }
button[aria-checked="true"], button[aria-pressed="true"] {
background: var(--rs-item-selection-bg);
color: var(--rs-text-strong);
box-shadow: inset 0 -2px 0 var(--rs-accent);
}
.split { height: 32px; border: 1px solid var(--rs-border); }
@container (max-width: 560px) {
.label { display: none; }
button { padding: 0 6px; }
}
</style>