diff --git a/docs/design-decisions.md b/docs/design-decisions.md index 6f5614f..fd27460 100644 --- a/docs/design-decisions.md +++ b/docs/design-decisions.md @@ -934,3 +934,19 @@ Native shell, background image, and desktop acceptance remain open. - Evidence: `tests/smoke/layout/viewModes.smoke.mjs`, `tests/unit/layout/documentPanes.spec.ts`, and `tests/unit/layout/settings.spec.ts`. - Replaces / replaced by: `ModeSwitcher.svelte` and its hover test. - Limits: Split now shows Write beside Read when Write is the editor. Choose Source for the former source and preview layout. Browser checks use desktop service mocks. + +### UI-050 — Global actions, tabs, and platform title bars + +- Type: Rule change +- Date: 2026-10-28 +- Status: Implemented for user review +- Decision source: Owner decisions 3, 7, and 12 of 2026-10-27 (interface review issues 3, 8, and 15), stage 5-4. +- Previous rule: The workspace button, Help, and Settings sat in the footer of the left pane, so they left the window with the pane. The plugin ribbon had no width without plugin entries. Tabs could shrink to 69 pixels, with no list and no sign of hidden tabs. The fixed drag area was 40 pixels. Every platform got rounded 40-pixel caption buttons, and macOS got Windows caption buttons. +- New rule: The workspace button sits at the left end of the header. It shows the workspace name and opens the workspace list below it. The left ribbon is always present: plugin views at the top, Help and Settings at the bottom. Tabs keep 120 pixels and scroll, with fades at the ends and a ⌄ list of all tabs that marks pinned and unsaved tabs. The header keeps a drag area of 120 pixels after the tabs. In a narrow header, the tabs shrink first, and the drag area keeps at least 48 pixels. Windows and Linux get square caption buttons, 46 pixels wide and full height. macOS keeps its native traffic lights through an overlay title bar, and each title bar leaves `--rs-titlebar-inset-start` (78 pixels) free for them. +- Snap Layouts: The custom title bar has no native caption buttons, so a hit test cannot show the flyout. When the pointer rests 500 ms on maximize, the host presses Win+Z for the focused window. This is the method of the existing Win+H dictation command. +- Reason: Global actions must stay reachable when the side pane closes. A tab label must stay readable. Each platform keeps its own window conventions. +- Scope: The main header, the left ribbon, the tab bars, the Settings and Browser window title bars, and the window builders of the host. +- Shared implementation: `WorkbenchHeader.svelte`, `PluginRibbon.svelte`, `TabBar.svelte`, `WindowControls.svelte`, `src-tauri/src/window_frame.rs`, `src-tauri/tauri.macos.conf.json`, and the `--rs-titlebar-inset-start` token. +- 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. diff --git a/docs/menu-surfaces.json b/docs/menu-surfaces.json index ab5a20f..993bf1c 100644 --- a/docs/menu-surfaces.json +++ b/docs/menu-surfaces.json @@ -112,10 +112,10 @@ }, "RuneStone/src/lib/layout/TabBar.svelte": { "counts": { - "action": 1 + "action": 2 }, - "design": "Shared action menu", - "check": "tests/smoke/menus/consistency.smoke.mjs" + "design": "Shared action menu for tab actions and the list of all tabs", + "check": "tests/smoke/menus/consistency.smoke.mjs; tests/smoke/layout/titleBar.smoke.mjs" }, "RuneStone/src/lib/layout/Workbench.svelte": { "counts": { diff --git a/docs/ui-design.md b/docs/ui-design.md index 7f375c8..883ba5e 100644 --- a/docs/ui-design.md +++ b/docs/ui-design.md @@ -139,9 +139,12 @@ Decisions: [UI-002](design-decisions.md#ui-002--share-the-requested-dropdown-des ## Window and navigation -- The main header holds navigation, document tabs, actions, and window controls. +- The main header holds the workspace button, navigation, document tabs, actions, and window controls. The workspace button names the window and opens the workspace list. +- The left ribbon stays visible when the side pane is closed. It holds plugin views at the top and Help and Settings at the bottom. +- Tabs keep a minimum width of 120 pixels and scroll. Fades show tabs out of view, and ⌄ lists all tabs. A drag area of 120 pixels sits after the tabs. In a narrow header, the tabs shrink first, and the drag area keeps at least 48 pixels. +- Windows and Linux title bars use square caption buttons, 46 pixels wide and full height. Rest the pointer on maximize for Snap Layouts on Windows 11. macOS keeps its native traffic lights, and title bars leave `--rs-titlebar-inset-start` free for them. - Files, Search, Bookmarks, and installed sidebar views such as Git share the top navigation group. The active navigation button shows which view fills the left pane. -- Plugin editor views can use the vertical plugin ribbon. The ribbon has no width when it has no entries. +- Plugin editor views can use the left ribbon. - The built-in browser opens from its own toolbar action. Project Management opens from Plug-in views. Keep Plug-in views in the toolbar, away from the new-tab button. - Document and plugin tabs share the tab bar. The new-tab button follows the tabs. Tabs keep their order and pin state when a plugin replaces its view. - The main window keeps an empty New tab after its last tab closes. A secondary window closes with its last tab. The unsaved-edit and active-terminal confirmations still apply, and Cancel keeps the tab open. diff --git a/docs/user-guide.md b/docs/user-guide.md index c3e69a4..6878254 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -22,7 +22,7 @@ This guide explains how to work with files, documents, tabs, settings, and the b A workspace is a folder on your computer. RuneStone reads and writes its files directly. -1. Select the folder button at the bottom of the sidebar, or press Ctrl+O. +1. Select the workspace name at the left end of the title bar, or press Ctrl+O. 2. Choose a recent workspace, **Open another folder…**, or **New workspace…**. Each workspace opens in its own window. The current window keeps its documents and terminals. @@ -145,6 +145,7 @@ Each open tab keeps its undo history, cursor, and scroll position. | Close the tab | Ctrl+W | | Reorder | Drag the tab. Press Escape to cancel. With a tab focused, press Alt+Shift+Left or Alt+Shift+Right. | | Pin, close others, or close all | Right-click the tab. | +| Find a tab | Select ⌄ after the tabs for a list of all tabs. The list marks pinned and unsaved tabs. Fades at the ends of the tab strip show that more tabs are out of view. | | Move to a new window | Drag the tab out of the tab strip, or right-click it and choose **Open in new window**. | | Move to another window | Drag the tab to the tab strip of the other window. | @@ -187,7 +188,7 @@ If a write fails, your edits stay in the tab. RuneStone does not lock files, so ## Change settings -Select the gear at the bottom of the sidebar, or press Ctrl+,. Use the search field to find a setting. +Select the gear at the bottom of the left ribbon, or press Ctrl+,. Use the search field to find a setting. Settings apply to all workspaces on this computer and update all open windows. | Category | Settings | @@ -248,6 +249,6 @@ The [Terminal guide](guides/terminal.md) lists the terminal shortcuts. ## Get help -Press F1, or select the question mark at the bottom of the sidebar, for **Help and about**. It shows the app version, basic steps, and every shortcut. +Press F1, or select the question mark at the bottom of the left ribbon, for **Help and about**. It shows the app version, basic steps, and every shortcut. When you report a problem, include the app version, operating system, steps, expected result, and error text. diff --git a/src-tauri/build.rs b/src-tauri/build.rs index 53672f6..5cd13a7 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -25,6 +25,7 @@ fn main() { "spelling_menu_select", "spelling_menu_uninstall", "settings_open_window", + "window_snap_layouts", "settings_read", "settings_write", "settings_migrate", diff --git a/src-tauri/capabilities/browser.json b/src-tauri/capabilities/browser.json index 05e1f99..e4bf168 100644 --- a/src-tauri/capabilities/browser.json +++ b/src-tauri/capabilities/browser.json @@ -11,6 +11,7 @@ "allow-browser-stop", "allow-plugins-snapshot", "allow-settings-read", + "allow-window-snap-layouts", "allow-settings-write", "allow-settings-migrate", "allow-spelling-menu-install", diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 4dacfae..3119cd7 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -14,6 +14,7 @@ "allow-spelling-menu-select", "allow-spelling-menu-uninstall", "allow-settings-open-window", + "allow-window-snap-layouts", "allow-settings-read", "allow-settings-write", "allow-settings-migrate", diff --git a/src-tauri/capabilities/settings.json b/src-tauri/capabilities/settings.json index 3b6cb16..c32dcd5 100644 --- a/src-tauri/capabilities/settings.json +++ b/src-tauri/capabilities/settings.json @@ -9,6 +9,7 @@ "permissions": [ "allow-theme-export", "allow-settings-read", + "allow-window-snap-layouts", "allow-settings-write", "allow-settings-migrate", "core:default", diff --git a/src-tauri/permissions/autogenerated/window_snap_layouts.toml b/src-tauri/permissions/autogenerated/window_snap_layouts.toml new file mode 100644 index 0000000..ca33033 --- /dev/null +++ b/src-tauri/permissions/autogenerated/window_snap_layouts.toml @@ -0,0 +1,11 @@ +# Automatically generated - DO NOT EDIT! + +[[permission]] +identifier = "allow-window-snap-layouts" +description = "Enables the window_snap_layouts command without any pre-configured scope." +commands.allow = ["window_snap_layouts"] + +[[permission]] +identifier = "deny-window-snap-layouts" +description = "Denies the window_snap_layouts command without any pre-configured scope." +commands.deny = ["window_snap_layouts"] diff --git a/src-tauri/src/browser.rs b/src-tauri/src/browser.rs index 8b0396b..03e0e65 100644 --- a/src-tauri/src/browser.rs +++ b/src-tauri/src/browser.rs @@ -479,8 +479,8 @@ impl BrowserState { url.query_pairs_mut().append_pair("browserWindow", "true"); url.query_pairs_mut().append_pair("browserTab", id); if args["pinned"] == true { url.query_pairs_mut().append_pair("browserPinned", "true"); } - let result = tauri::WebviewWindowBuilder::new(app, &label, tauri::WebviewUrl::App(format!("?{}", url.query().unwrap_or_default()).into())) - .title("RuneStone Browser").inner_size(1100.0, 750.0).min_inner_size(500.0, 300.0).decorations(false).disable_drag_drop_handler().build(); + let result = crate::window_frame::title_bar(tauri::WebviewWindowBuilder::new(app, &label, tauri::WebviewUrl::App(format!("?{}", url.query().unwrap_or_default()).into()))) + .title("RuneStone Browser").inner_size(1100.0, 750.0).min_inner_size(500.0, 300.0).disable_drag_drop_handler().build(); if let Err(error) = result { worker.routing.lock()?.close(&label); return Err(Error::from(error)); diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 5362f36..595f656 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -15,6 +15,7 @@ mod spelling; mod theme; mod backgrounds; mod folders; +mod window_frame; use pty::PtyState; use tauri::Manager; @@ -54,6 +55,7 @@ pub fn run() { spelling::spelling_menu_select, spelling::spelling_menu_uninstall, settings::settings_open_window, + window_frame::window_snap_layouts, preferences::settings_read, preferences::settings_write, preferences::settings_migrate, diff --git a/src-tauri/src/settings.rs b/src-tauri/src/settings.rs index 18d43a1..83d9c24 100644 --- a/src-tauri/src/settings.rs +++ b/src-tauri/src/settings.rs @@ -86,13 +86,12 @@ pub async fn settings_open_window( let title = root.as_ref() .and_then(|root| root.file_name().map(|name| format!("Settings — {} — RuneStone", name.to_string_lossy()))) .unwrap_or_else(|| "Settings — RuneStone".into()); - match tauri::WebviewWindowBuilder::new( + match crate::window_frame::title_bar(tauri::WebviewWindowBuilder::new( &app, &label, tauri::WebviewUrl::App("?settingsWindow=true".into()), - ) + )) .title(title) .inner_size(920.0, 650.0) .min_inner_size(540.0, 420.0) - .decorations(false) .resizable(true) .visible(false) .disable_drag_drop_handler() diff --git a/src-tauri/src/window_frame.rs b/src-tauri/src/window_frame.rs new file mode 100644 index 0000000..cc66517 --- /dev/null +++ b/src-tauri/src/window_frame.rs @@ -0,0 +1,31 @@ +//! The window frame: the title bar style of each platform, and Snap Layouts on Windows 11. +use crate::error::Result; + +/// Give a window that RuneStone builds at run time the title bar of its platform. +/// Windows and Linux windows draw their own title bar. macOS keeps its native traffic lights over the web content. +pub fn title_bar<'a, R: tauri::Runtime, M: tauri::Manager>(builder: tauri::WebviewWindowBuilder<'a, R, M>) -> tauri::WebviewWindowBuilder<'a, R, M> { + #[cfg(target_os = "macos")] + { builder.title_bar_style(tauri::TitleBarStyle::Overlay).hidden_title(true) } + #[cfg(not(target_os = "macos"))] + { builder.decorations(false) } +} + +/// Open the Snap Layouts flyout of the focused window, as a native maximize button does on hover. +/// The custom title bar has no native caption buttons, so the host presses Win+Z. A window without focus does nothing. +#[tauri::command] +pub fn window_snap_layouts(window: tauri::Window) -> Result<()> { + #[cfg(windows)] + { + use windows_sys::Win32::UI::Input::KeyboardAndMouse::{keybd_event, KEYEVENTF_KEYUP, VK_LWIN}; + if !window.is_focused().map_err(crate::error::Error::from_display)? { return Ok(()); } + unsafe { + keybd_event(VK_LWIN as u8, 0, 0, 0); + keybd_event(b'Z', 0, 0, 0); + keybd_event(b'Z', 0, KEYEVENTF_KEYUP, 0); + keybd_event(VK_LWIN as u8, 0, KEYEVENTF_KEYUP, 0); + } + } + #[cfg(not(windows))] + { let _ = window; } + Ok(()) +} diff --git a/src-tauri/tauri.macos.conf.json b/src-tauri/tauri.macos.conf.json new file mode 100644 index 0000000..4feeeb3 --- /dev/null +++ b/src-tauri/tauri.macos.conf.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://schema.tauri.app/config/2", + "app": { + "windows": [ + { + "title": "RuneStone", + "width": 1400, + "height": 900, + "minWidth": 880, + "minHeight": 560, + "titleBarStyle": "Overlay", + "hiddenTitle": true, + "dragDropEnabled": false + } + ] + } +} diff --git a/src/lib/i18n/messages.ts b/src/lib/i18n/messages.ts index 2099251..3461411 100644 --- a/src/lib/i18n/messages.ts +++ b/src/lib/i18n/messages.ts @@ -941,12 +941,6 @@ export const messageRows: [string, string, string, string][] = [ "フォルダーを開く", "打开文件夹" ], - [ - "No workspace", - "Aucun espace de travail", - "ワークスペースなし", - "无工作区" - ], [ "Help and about ({shortcut})", "Aide et à propos ({shortcut})", @@ -3464,6 +3458,9 @@ export const messageRows: [string, string, string, string][] = [ ["Split: Read beside the editor", "Diviser : Lire à côté de l’éditeur", "分割: エディターの横に閲覧を表示", "分栏:在编辑器旁显示阅读"], ["Switch between Write and Source", "Alterner entre Écrire et Source", "「書く」と「ソース」を切り替え", "在写作和源码之间切换"], ["Switch between Read and the editor", "Alterner entre Lire et l’éditeur", "「閲覧」とエディターを切り替え", "在阅读和编辑器之间切换"], + ["Unsaved", "Non enregistré", "未保存", "未保存"], + ["All tabs", "Tous les onglets", "すべてのタブ", "所有标签页"], + ["Open folder ({shortcut})", "Ouvrir un dossier ({shortcut})", "フォルダーを開く ({shortcut})", "打开文件夹 ({shortcut})"], ]; export const catalogs: Record, Record> = { fr: Object.fromEntries(messageRows.map(row => [row[0], row[1]])), diff --git a/src/lib/layout/BrowserWindow.svelte b/src/lib/layout/BrowserWindow.svelte index cd97b0d..b03e879 100644 --- a/src/lib/layout/BrowserWindow.svelte +++ b/src/lib/layout/BrowserWindow.svelte @@ -110,9 +110,9 @@ diff --git a/src/lib/layout/SettingsDialog.svelte b/src/lib/layout/SettingsDialog.svelte index bfda8ee..079d857 100644 --- a/src/lib/layout/SettingsDialog.svelte +++ b/src/lib/layout/SettingsDialog.svelte @@ -203,7 +203,7 @@ dialog.standalone { width: 100vw; height: 100dvh; margin: 0; border: 0; border-radius: 0; box-shadow: none; } dialog.help { width: min(650px, calc(100vw - 32px)); } header { height: var(--rs-titlebar-height); padding: 0 4px 0 12px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--rs-border); background: var(--rs-bg-elevated); } - header.window-header { padding-right: 0; user-select: none; } + header.window-header { padding-right: 0; padding-left: calc(12px + var(--rs-titlebar-inset-start)); user-select: none; } h1 { font-size: 13px; font-weight: 600; margin: 0; } .body { display: flex; height: calc(100% - var(--rs-titlebar-height)); min-height: 0; } aside { width: 220px; flex-shrink: 0; padding: 12px 8px; background: var(--rs-bg-elevated); border-right: 1px solid var(--rs-border); display: flex; flex-direction: column; overflow: auto; } diff --git a/src/lib/layout/TabBar.svelte b/src/lib/layout/TabBar.svelte index a79eeb8..c80544d 100644 --- a/src/lib/layout/TabBar.svelte +++ b/src/lib/layout/TabBar.svelte @@ -149,9 +149,40 @@ $effect(() => { const path = activePath; - if (path) void tick().then(() => tabButton(path)?.scrollIntoView({ block: "nearest", inline: "nearest" })); + // Scroll the whole tab into view, with its close button. + if (path) void tick().then(() => tabButton(path)?.closest(".tab")?.scrollIntoView({ block: "nearest", inline: "nearest" })); }); + // Fades at the ends of the tab strip show that more tabs are out of view. + let fadeStart = $state(false), fadeEnd = $state(false); + function measureOverflow() { + fadeStart = bar.scrollLeft > 1; + fadeEnd = bar.scrollLeft + bar.clientWidth < bar.scrollWidth - 1; + } + $effect(() => { + void tabs.length; + const observer = new ResizeObserver(measureOverflow); + observer.observe(bar); + measureOverflow(); + return () => observer.disconnect(); + }); + + // The list of all tabs: the current tab is checked, and the rows name pinned and unsaved tabs. + let allTabsButton = $state(); + function showAllTabs() { + if (menu && menuAnchor === allTabsButton) { closeMenu(true); return; } + cancelDrag(); + closeMenu(); + 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, + // As with a click on the tab, the workbench then focuses the document. + run: () => { closeMenu(); onSelect(tab.relPath); }, + })), () => closeMenu(true), $t("All tabs")); + } + async function move(path: string, index: number) { onMove(path, index); await tick(); @@ -321,7 +352,7 @@ ondragleave={(event) => { if (!event.relatedTarget) clearTransferTarget(); }} ondragend={clearTransferTarget} /> -
{ if (!(event.relatedTarget instanceof Node) || !bar.contains(event.relatedTarget)) { receiving = false; dropBefore = dropAfter = null; } }}> {#each tabs as tab (tab.id)} @@ -370,6 +401,12 @@
{/each} +{#if tabs.length > 1} + +{/if} {announcement} diff --git a/src/lib/layout/Workbench.svelte b/src/lib/layout/Workbench.svelte index 813f55b..b4bdf5e 100644 --- a/src/lib/layout/Workbench.svelte +++ b/src/lib/layout/Workbench.svelte @@ -89,7 +89,7 @@ } let settings = $state({ ...DEFAULT_SETTINGS }); let settingsReady = $state(false); - let workspaceAnchor: HTMLDivElement | undefined = $state(); + let workspaceAnchor: HTMLButtonElement | undefined = $state(); const desktop = isTauri(); const transferredWindow = /^[0-9a-f-]{36}$/i.test(new URLSearchParams(location.search).get("tabTransfer") ?? ""); // The documents of the open workspace. Their buffers are reactive, so the tabs read them directly. @@ -1093,7 +1093,7 @@ const shell = event.currentTarget as HTMLElement; const rect = shell.getBoundingClientRect(); if (dragging === "left") { - leftWidth = Math.min(480, Math.max(160, event.clientX - rect.left - (ribbonNavigation.length ? 44 : 0))); + leftWidth = Math.min(480, Math.max(160, event.clientX - rect.left - 44)); } if (dragging === "right") { rightWidth = Math.min(480, Math.max(160, rect.right - event.clientX)); @@ -1209,7 +1209,7 @@
0} + class:has-ribbon={!transferredWindow} class:left-open={!transferredWindow && leftOpen} class:right-open={!transferredWindow && rightOpen} role="application" @@ -1225,6 +1225,9 @@ error = message} /> - {#if !transferredWindow}{/if} + {#if !transferredWindow} preferences = "help"} onSettings={() => void openSettings()} />{/if} {#if leftOpen && !transferredWindow} { void saveTemplate(entry); }} onManageTemplates={() => templateManager = true} onStatus={(message) => { status = message; error = null; }} - onChooseWorkspace={chooseWorkspace} - onHelp={() => preferences = "help"} - onSettings={() => void openSettings()} />
- // The workbench header: the side pane buttons, the working tabs, the actions, and the window controls. + // The workbench header: the workspace button, the side pane buttons, the working tabs, the actions, and the window controls. import type { ComponentProps } from "svelte"; import { t } from "$lib/i18n"; + import Icon from "$lib/ui/Icon.svelte"; import IconButton from "$lib/ui/IconButton.svelte"; + import { attachTooltip } from "$lib/ui/tooltip"; import WindowControls from "$lib/ui/WindowControls.svelte"; import PluginTools from "$lib/plugins/PluginTools.svelte"; import PluginAccessMenu from "$lib/plugins/PluginAccessMenu.svelte"; @@ -14,6 +16,9 @@ type Props = { detached: boolean; desktop: boolean; + workspaceName: string | null; + workspaceAnchor?: HTMLButtonElement; + onChooseWorkspace: () => void; leftOpen: boolean; leftView: LeftView; sidebarNavigation: { owner: string; id: string; title: string; icon?: string }[]; @@ -32,13 +37,24 @@ onToggleRight: () => void; onError: (message: string) => void; }; - let { detached, desktop, leftOpen, leftView, sidebarNavigation, onSelectLeft, tabBar, onNewTab, canOpenBrowser, browserOpening, onOpenBrowser, + let { detached, desktop, workspaceName, workspaceAnchor = $bindable(), onChooseWorkspace, leftOpen, leftView, sidebarNavigation, onSelectLeft, tabBar, onNewTab, canOpenBrowser, browserOpening, onOpenBrowser, saveDisabled, onSave, terminalEnabled, terminalOpen, onToggleTerminal, rightOpen, onToggleRight, onError }: Props = $props(); + + function tooltip(node: HTMLElement, text: string) { + let current = text; + const dispose = attachTooltip(node, () => current); + return { update(value: string) { current = value; }, destroy: dispose }; + }
{#if !detached} + + onSelectLeft("files")} /> onSelectLeft("search")} /> onSelectLeft("bookmarks")} /> @@ -55,7 +71,7 @@
- {#if desktop}
{/if} + {#if desktop}{/if}
{#if canOpenBrowser}{/if} @@ -91,8 +107,33 @@ min-width: 0; padding: 0 4px; } + /* The macOS traffic lights sit at the start of the header (src/lib/theme/tokens.css). */ + .header-left { justify-content: flex-start; padding-left: calc(4px + var(--rs-titlebar-inset-start)); } + .workspace-button { + display: inline-flex; + flex: 0 1 auto; + align-items: center; + gap: 6px; + min-width: 32px; + max-width: 180px; + height: 28px; + margin-right: 4px; + padding: 0 6px; + border: 1px solid transparent; + border-radius: var(--rs-control-radius); + background: transparent; + color: var(--rs-text); + font: 600 12px var(--rs-font-ui); + } + .workspace-button:hover { background: var(--rs-bg-active); border-color: var(--rs-border); } + .workspace-button :global(svg) { width: 16px; height: 16px; flex-shrink: 0; color: var(--rs-text-dim); } + .workspace-button :global(svg:last-child) { width: 12px; height: 12px; } + .ws { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } + + /* In a window below the minimum width, the center clips its content instead of drawing under the right group. */ .header-center { + overflow: hidden; display: flex; align-items: center; justify-content: flex-start; @@ -105,15 +146,17 @@ .header-left, .header-center, .header-right { height: 100%; } /* The left group spans the ribbon and the open left pane (the shell sets the widths). */ - :global(.shell.left-open) .header-left { width: calc(var(--ribbon-width) + var(--left) + 1px); padding-left: calc(var(--ribbon-width) + 4px); } + :global(.shell.left-open) .header-left { width: calc(var(--ribbon-width) + var(--left) + 1px); } .header-left :global(.icon-btn), .header-right :global(.icon-btn) { flex-shrink: 0; } .header-right { justify-content: flex-end; } - .window-drag-space { flex: 0 0 40px; align-self: stretch; } + /* A drag area keeps the window movable when the tabs fill the header: 120 pixels, and at least 48 in a narrow header. */ + .window-drag-space { flex: 0 1 120px; min-width: 48px; align-self: stretch; } + /* The tab strip keeps room for one readable tab. It shrinks first, so the drag area shrinks only after it. */ .header-center :global(.tabs) { - flex: 0 1 auto; + flex: 0 1000 auto; align-self: stretch; - min-width: 0; + min-width: 120px; min-height: 28px; background: transparent; border-bottom: 0; @@ -121,7 +164,7 @@ .header-center :global(.tab) { flex: 0 1 180px; width: 180px; - min-width: 96px; + min-width: 120px; max-width: 180px; background: transparent; } diff --git a/src/lib/layout/WorkspacePicker.svelte b/src/lib/layout/WorkspacePicker.svelte index 28fcf11..8f11df0 100644 --- a/src/lib/layout/WorkspacePicker.svelte +++ b/src/lib/layout/WorkspacePicker.svelte @@ -46,7 +46,10 @@ function position() { const rect = anchor?.getBoundingClientRect(); menu.style.left = `${Math.max(8, Math.min(rect?.left ?? (innerWidth - menu.offsetWidth) / 2, innerWidth - menu.offsetWidth - 8))}px`; - menu.style.top = `${Math.max(8, (rect?.top ?? (innerHeight + menu.offsetHeight) / 2) - menu.offsetHeight - 8)}px`; + // The list opens below an anchor in the title bar, and above an anchor lower in the window. + const below = rect ? rect.bottom + 4 : (innerHeight - menu.offsetHeight) / 2; + const top = rect && rect.top > innerHeight / 2 ? rect.top - menu.offsetHeight - 8 : below; + menu.style.top = `${Math.max(8, Math.min(top, innerHeight - menu.offsetHeight - 8))}px`; } function close() { menu.hidePopover(); returnFocus?.focus(); } diff --git a/src/lib/theme/tokens.css b/src/lib/theme/tokens.css index 8486f44..4dc2a3d 100644 --- a/src/lib/theme/tokens.css +++ b/src/lib/theme/tokens.css @@ -21,6 +21,8 @@ --rs-workarea-surface-opacity: 100%; --rs-workarea-plugin-bg: var(--rs-bg); --rs-titlebar-height: 36px; + /* The space at the start of a title bar for the macOS traffic lights (src/routes/+layout.svelte). */ + --rs-titlebar-inset-start: 0px; --rs-settings-row-padding: 10px; --rs-settings-control-height: 28px; --rs-settings-heading-size: 18px; @@ -101,3 +103,6 @@ --rs-caption-close-bg: #c42b1c; --rs-image-viewer-bg: #090a0de8; } + +/* macOS draws its traffic lights over the start of each title bar. */ +:root[data-title-bar="mac"] { --rs-titlebar-inset-start: 78px; } diff --git a/src/lib/ui/WindowControls.svelte b/src/lib/ui/WindowControls.svelte index bdf5bd9..636e749 100644 --- a/src/lib/ui/WindowControls.svelte +++ b/src/lib/ui/WindowControls.svelte @@ -1,12 +1,19 @@ -
- void run("minimize")} /> - void run("toggleMaximize")} /> -
- void run("close")} /> +{#if !mac} +
+ void run("minimize")} /> + +
+ void run("close")} /> +
-
+{/if} diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 5ffab81..5be7f01 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -2,10 +2,14 @@ import "../app.css"; import ThemeSync from "$lib/theme/ThemeSync.svelte"; import { onMount } from "svelte"; + import { isTauri } from "@tauri-apps/api/core"; + import { isMac } from "$lib/ui/shortcuts"; import { isSpellingTarget, mountSpellingMenu } from "$lib/editor/spellingMenu"; let { children } = $props(); onMount(mountSpellingMenu); + // On macOS the native traffic lights sit over the title bar (src-tauri/tauri.macos.conf.json). + if (isTauri() && isMac()) document.documentElement.dataset.titleBar = "mac"; { if (!isSpellingTarget(event.target)) event.preventDefault(); }} /> diff --git a/tests/smoke/appearance/themeEditor.smoke.mjs b/tests/smoke/appearance/themeEditor.smoke.mjs index cb4fb80..59f6dcc 100644 --- a/tests/smoke/appearance/themeEditor.smoke.mjs +++ b/tests/smoke/appearance/themeEditor.smoke.mjs @@ -88,12 +88,16 @@ await runSmoke("appearance/themeEditor", async ({ browser }) => { await settings.waitForFunction(() => document.documentElement.dataset.palette === "custom:runestone-dark-copy-copy"); assert.equal((await main.evaluate(() => window.__TEST__.settings("customThemes"))).length, 2); - // Narrow windows keep the editor inside the window, and keyboard focus is visible. - await main.setViewportSize({ width: 600, height: 760 }); + // A narrow pane keeps the editor inside the window, and keyboard focus is visible. + // A 520-pixel window without the outline leaves the editor about 215 pixels, below its 240-pixel breakpoint. + await main.getByRole("button", { name: "Hide outline", exact: true }).click(); + await main.setViewportSize({ width: 520, height: 760 }); + assert.ok(await editor.evaluate(node => node.clientWidth <= 240)); await hex("accent").focus(); - assert.equal(await editor.evaluate(node => node.scrollWidth <= node.clientWidth + 1), true, "The editor does not scroll sideways at 600 pixels"); + assert.equal(await editor.evaluate(node => node.scrollWidth <= node.clientWidth + 1), true, "The editor does not scroll sideways in a narrow pane"); assert.notEqual(await hex("accent").evaluate(node => getComputedStyle(node).outlineStyle), "none"); - await main.screenshot({ path: path.join(output, "editor-600.png") }); + await main.screenshot({ path: path.join(output, "editor-narrow.png") }); + await main.setViewportSize({ width: 1200, height: 820 }); await settings.setViewportSize({ width: 360, height: 640 }); assert.equal(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "Narrow settings do not overflow"); const box = await cards.boundingBox(); diff --git a/tests/smoke/layout/outline.smoke.mjs b/tests/smoke/layout/outline.smoke.mjs index e296bd5..dcf5679 100644 --- a/tests/smoke/layout/outline.smoke.mjs +++ b/tests/smoke/layout/outline.smoke.mjs @@ -54,7 +54,8 @@ await runSmoke("layout/outline", async ({ browser }) => { console.log("PASS: hidden outline survives reload and window reopen"); await page.getByRole("button", { name: "Show outline", exact: true }).click(); - await resize(0, 330); + // The left ribbon is 44 pixels wide, so the gutter at 374 gives a 330-pixel side pane. + await resize(0, 374); await resize(1, 970); const resized = await widths(); assert.deepEqual(resized, ["330px", "310px"]); diff --git a/tests/smoke/layout/titleBar.smoke.mjs b/tests/smoke/layout/titleBar.smoke.mjs new file mode 100644 index 0000000..79c9af5 --- /dev/null +++ b/tests/smoke/layout/titleBar.smoke.mjs @@ -0,0 +1,121 @@ +// The title bar: the workspace button, the left ribbon, readable tabs with a list of all tabs, the drag area, caption buttons, Snap Layouts, and the macOS layout. +import assert from "node:assert/strict"; +import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs"; + +const names = ["meeting-notes", "research-plan", "inbox", "field-notes", "weekly-review", "reading-list", "project-ideas", "travel", "budget", "journal", "recipes"]; + +await runSmoke("layout/titleBar", async ({ browser }) => { + const output = await outputDir("layout/titleBar"); + const context = await browser.newContext({ viewport: { width: 1280, height: 720 } }); + await mockTauri(context, { + state: { names }, + commands: test => ({ + ...test.workspace({ root: "C:\\Users\\me\\Documents\\Field work", files: Object.fromEntries(test.state.names.map(name => [`notes/${name}.md`, `# ${name}\n\nText.\n`])) }), + plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }), + "plugin:window|is_maximized": () => false, + window_snap_layouts: () => null, + }), + }); + const page = await openPage(context); + async function open(name) { + await page.keyboard.press("Control+p"); + await page.getByRole("textbox", { name: "Find a file" }).fill(`${name}.md`); + await page.getByRole("dialog").getByRole("button").filter({ hasText: `${name}.md` }).first().click(); + await page.getByRole("tab", { name: `${name}.md`, exact: true, selected: true }).waitFor(); + } + const box = locator => locator.evaluate(node => { const rect = node.getBoundingClientRect(); return { x: rect.x, right: rect.right, width: rect.width, height: rect.height, bottom: rect.bottom }; }); + + await page.goto(smokeUrl); + // The workspace button is the first control of the header. It opens the workspace list below it. + const workspace = page.getByRole("button", { name: "Field work", exact: true }); + await workspace.waitFor(); + // Auto-save stays off, so the edited tab keeps its unsaved mark. + await page.evaluate(() => window.__TEST__.writeSettings("general", { autosaveEnabled: false, autosaveSeconds: 5 })); + assert.equal(await page.locator("header.header button").first().evaluate(node => node.classList.contains("workspace-button")), true); + await workspace.click(); + const picker = page.getByRole("dialog", { name: "Workspaces" }); + await picker.waitFor(); + assert.ok(await picker.evaluate((node, bottom) => node.getBoundingClientRect().top >= bottom, (await box(workspace)).bottom)); + await page.keyboard.press("Escape"); + + // Help and Settings stay in the left ribbon when the side pane closes. + await page.keyboard.press("Control+\\"); + await page.locator("aside.left").waitFor({ state: "detached" }); + const ribbon = page.locator(".plugin-ribbon"); + await ribbon.getByRole("button", { name: "Help and about (F1)", exact: true }).click(); + await page.getByRole("dialog", { name: "Help and about" }).waitFor(); + await page.getByRole("button", { name: "Close help", exact: true }).click(); + assert.equal(await ribbon.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).isVisible(), true); + assert.equal((await box(ribbon)).width, 44); + await page.keyboard.press("Control+\\"); + await page.locator("aside.left").waitFor(); + + // Tabs keep a readable width and scroll. Fades show hidden tabs, and the list names every tab. + for (const name of names) await open(name); + const widths = await page.locator("header .tab").evaluateAll(tabs => tabs.map(tab => tab.getBoundingClientRect().width)); + assert.ok(widths.every(width => width >= 120), JSON.stringify(widths)); + const strip = page.locator("header .tabs"); + assert.equal(await strip.evaluate(node => node.classList.contains("fade-start")), true); + assert.equal(await strip.evaluate(node => node.classList.contains("fade-end")), false, "The active last tab is in view with its close button"); + await page.locator(".cm-content").click(); + await page.keyboard.type("Edit "); + // An unsaved tab adds " •" to its name. + await page.getByRole("tab", { name: /^recipes.md/ }).click({ button: "right" }); + await page.getByRole("menuitem", { name: "Pin", exact: true }).click(); + await page.getByRole("button", { name: "All tabs", exact: true }).click(); + const list = page.getByRole("menu", { name: "All tabs", exact: true }); + await list.waitFor(); + assert.equal(await list.getByRole("menuitemradio").count(), names.length); + const recipes = list.getByRole("menuitemradio", { name: /^recipes\.md/ }); + assert.equal(await recipes.getAttribute("aria-checked"), "true"); + assert.match(await recipes.innerText(), /Unsaved/); + assert.equal(await recipes.locator("svg").count(), 1, "The pinned tab shows the pin icon"); + await page.screenshot({ path: `${output}/all-tabs.png` }); + await list.getByRole("menuitemradio", { name: "inbox.md", exact: true }).click(); + await page.getByRole("tab", { name: "inbox.md", exact: true, selected: true }).waitFor(); + await list.waitFor({ state: "detached" }); + assert.equal(await strip.evaluate(node => node.classList.contains("fade-end")), true); + + // A fixed drag area follows the tabs. Caption buttons are square and fill the title bar height. + const drag = page.locator(".window-drag-space"); + assert.equal(Math.round((await box(drag)).width), 120); + assert.equal(await drag.getAttribute("data-tauri-drag-region"), ""); + const captions = await page.locator(".window-controls .icon-btn").evaluateAll(buttons => buttons.map(button => ({ width: button.getBoundingClientRect().width, height: button.getBoundingClientRect().height, radius: getComputedStyle(button).borderRadius }))); + const height = (await box(page.locator("header.header"))).height; + assert.deepEqual(captions, Array(3).fill({ width: 46, height, radius: "0px" })); + // Resting on maximize asks the host for Snap Layouts. A short pass does not. + const calls = () => page.evaluate(() => window.__TEST__.calls.filter(call => call.command === "window_snap_layouts").length); + await page.getByRole("button", { name: "Maximize window", exact: true }).hover(); + await page.mouse.move(600, 400); + await page.waitForTimeout(700); + assert.equal(await calls(), 0); + await page.getByRole("button", { name: "Maximize window", exact: true }).hover(); + await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === "window_snap_layouts")); + await page.mouse.move(600, 400); + + 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); + await page.locator("header.header").screenshot({ path: `${output}/header-${theme}.png` }); + } + await page.setViewportSize({ width: 880, height: 560 }); + assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)); + assert.ok((await box(page.locator(".window-controls"))).right <= 880); + await page.screenshot({ path: `${output}/narrow.png` }); + + // macOS keeps its native traffic lights: no caption buttons, and room at the start of the title bar. + const mac = await openPage(context); + await mac.addInitScript(() => { + Object.defineProperty(navigator, "platform", { get: () => "MacIntel" }); + Object.defineProperty(navigator, "userAgentData", { get: () => ({ platform: "macOS" }) }); + }); + await mac.goto(smokeUrl); + await mac.getByRole("button", { name: "Field work", exact: true }).waitFor(); + assert.equal(await mac.evaluate(() => document.documentElement.dataset.titleBar), "mac"); + assert.equal(await mac.locator(".window-controls").count(), 0); + assert.equal(await mac.locator(".header-left").evaluate(node => getComputedStyle(node).paddingLeft), "82px"); + assert.match(await mac.getByRole("button", { name: "Settings (⌘,)", exact: true }).getAttribute("aria-label"), /⌘/); + await mac.locator("header.header").screenshot({ path: `${output}/header-mac.png` }); + assert.deepEqual([...page.errors, ...mac.errors], []); + console.log("PASS: workspace button, permanent ribbon, readable tabs with fades and a list, fixed drag area, square caption buttons, Snap Layouts request, macOS layout, both themes, narrow window."); +}); diff --git a/tests/smoke/settings/titlebar.smoke.mjs b/tests/smoke/settings/titlebar.smoke.mjs index 719c281..1435629 100644 --- a/tests/smoke/settings/titlebar.smoke.mjs +++ b/tests/smoke/settings/titlebar.smoke.mjs @@ -60,7 +60,8 @@ await runSmoke("settings/titlebar", async ({ browser }) => { const control = dialog.getByRole("button", { name: label, exact: true }); const bounds = await control.boundingBox(); assert(bounds.x >= 0 && bounds.x + bounds.width <= size.width && bounds.height >= 28); - assert.notEqual(await control.evaluate(element => getComputedStyle(element).borderTopLeftRadius), "0px"); + // Caption buttons are square (src/lib/ui/WindowControls.svelte). + assert.equal(await control.evaluate(element => getComputedStyle(element).borderTopLeftRadius), "0px"); } await page.screenshot({ path: path.join(output, `${theme}-${size.width}.png`) }); } diff --git a/tests/smoke/workspace/openAndCreate.smoke.mjs b/tests/smoke/workspace/openAndCreate.smoke.mjs index 3d40cf2..54c7756 100644 --- a/tests/smoke/workspace/openAndCreate.smoke.mjs +++ b/tests/smoke/workspace/openAndCreate.smoke.mjs @@ -53,7 +53,8 @@ await runSmoke("workspace/openAndCreate", async ({ page }) => { const view = window.__EditorView.findFromDOM(document.querySelector(".source-editor .cm-content")); view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: "My pending edit" } }); }); - const trigger = page.getByRole("button", { name: "Open folder", exact: true }); + // The workspace button at the left of the header names the workspace (src/lib/layout/WorkbenchHeader.svelte). + const trigger = page.locator(".workspace-button"); const menu = page.getByRole("dialog", { name: "Workspaces", exact: true }); await page.evaluate(() => window.__TEST__.reorder()); await trigger.click();