diff --git a/CLAUDE.md b/CLAUDE.md index 214ea18..73ce1b0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -2,7 +2,7 @@ Clair is a macOS web browser in the style of Arc, built on ungoogled-chromium. It targets Apple Silicon only, with macOS 15.6 as the minimum. Its interface is native AppKit/SwiftUI in Crest's style (`pauljoda/Crest`): a Swift framework, `ClairUI`, that Chromium loads at start-up, with WebUI only for Chromium's internal pages. Change 1 uses it only for Sparkle 2 updates, the update menu and the About window. The UX spike (roadmap step 2 in change 1's `proposal.md`) replaces Chromium's window with a native one. -Every patch to an existing Chromium file is extra maintenance: it can conflict on each version bump and has to be fixed then. Creating or updating a patch is encouraged when it gets the behavior we want with cleaner code, but weigh that against the cost of carrying it. New source files go in `engine/overlay/`, and the native interface in `ClairUI`. +Patch Chromium whenever a change needs it. A patch to an existing Chromium file can conflict on a version bump and then has to be fixed, but that cost is expected and acceptable. Don't work around Chromium to avoid a patch: no duplicating its logic, contorting `ClairUI` or overlay code, or settling for weaker behavior. Prefer the patch whenever it gets the behavior we want with less or cleaner code. Keep each patch small and focused, so it is easy to rebase. New source files go in `engine/overlay/`, and the native interface in `ClairUI`. ## Planning: OpenSpec diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/.openspec.yaml b/openspec/changes/add-tab-switcher-and-tabs-menu/.openspec.yaml new file mode 100644 index 0000000..7ed429c --- /dev/null +++ b/openspec/changes/add-tab-switcher-and-tabs-menu/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-26 diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/arc-reference/README.md b/openspec/changes/add-tab-switcher-and-tabs-menu/arc-reference/README.md new file mode 100644 index 0000000..905ff8b --- /dev/null +++ b/openspec/changes/add-tab-switcher-and-tabs-menu/arc-reference/README.md @@ -0,0 +1,46 @@ +# Arc's tab switcher: reference screenshots + +Probed on 2026-11-26 with `tests/probe/` in the owner's Arc, Light Mode, a 963 × 976 pt window at the screen's top left (1920 × 1080 pt screen), 2 px per point. Real key events came from a small tool that holds Ctrl across Tab presses (design D8); XCUITest's `typeKey` releases its modifiers after each key. + +Set-up (by the owner): +- **Space "Probe A":** + - Favorites: Reuters and Ars Technica. + - Pinned: AP News (open) and AccuWeather (page closed). + - Today: a split of The New York Times and The Verge, then Apple, GitHub, Hacker News, Wikipedia "Cat", MDN, Example Domain and BBC. +- **Space "Probe B":** Weather.com and IMDb. + +Keep these screenshots. They move with the change when it's archived. + +## What Arc does + +- **Contents.** Ctrl+Tab shows the window's 5 most recently shown tabs, the shown tab first, the second selected. Seven visited tabs gave five cards. +- **Scope.** Recents span Spaces: from "Probe A", Weather.com of "Probe B" was listed, and choosing it switched the window to "Probe B". Favorites (Reuters) and open pinned tabs (AP News) are listed. +- **Closed pages.** Closing a pinned tab's page (Cmd+W, Close and Keep Pinned) took it off the list. +- **Splits.** A split is one card: both pages side by side in one preview, and both favicons with no title. +- **Stepping.** Each Tab, Ctrl held, selects the next card. Tab on the last card wraps to the first. Ctrl+Shift+Tab opens with the last card selected, and Tab then wraps to the first. +- **Committing.** Releasing Ctrl shows the selected tab, and a quick Ctrl+Tab shows the previous tab without the panel. Recorded at 60 fps with Ctrl released about 50, 90, 130, 180 and 280 ms after Tab: no panel at 50 or 90 ms; at 130 ms it showed for 3 frames, at 180 ms for 5, at 280 ms for 13. The delay is therefore between 90 and 130 ms. +- **Cancelling.** Esc, Ctrl still held, closes the panel and keeps the tab. +- **The pointer.** Clicking a card chooses it (the owner checked by hand). The probe's synthetic XCUITest click on a card did nothing, so don't trust the probe for this. +- **Animation.** None. In a 60 fps recording, the panel appears in one frame, the selection moves in one frame, and the panel is gone in the frame after Ctrl is released. +- **Two tabs.** In a window with two recent tabs, the panel held two cards and was centred on the window. + +## Measurements (points) + +| What | Value | +|---|---| +| Panel, five cards | 938 × 189, x 41–979, y 424–612 on screen. The window spans x 0–963, y 30–1006, so the panel is vertically centred on the window, but sits about 29 pt right of the window's centre and overhangs its right edge. | +| Panel padding | 27 to a card's preview; the selection highlight comes 15–16 from the panel's edges | +| Panel corners | about 22, hairline grey border, soft shadow, background #F2F2F2 | +| Card preview | 157.5 × 105 (3:2), the page's top edge, fitted to width, corners about 5 | +| Card pitch | 181.5 (24 between previews) | +| Label | 16 favicon, then the title in about the sidebar's title size, one line, with an ellipsis. Selected: darker and bolder. | +| Selection highlight | 181.5 × 157.5, 12 around the preview, about 12 corners, the Space's light accent (lavender here) | + +## Screenshots + +Only two are kept. The rest of what was probed (stepping, Shift+Tab, Esc, a closed pinned page leaving the list, the recording's frames) is described above. + +| File | Shows | +|---|---| +| switcher-whole-panel.jpg | The whole panel from a screen capture, overhanging the window's right edge, with MDN selected: corners, border, highlight and the full card row | +| switcher-across-spaces.jpg | From "Probe A": the split's card (two favicons, no title), Weather.com of "Probe B" selected, AP News (pinned), Reuters (favorite), BBC | diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/arc-reference/screenshots/switcher-across-spaces.jpg b/openspec/changes/add-tab-switcher-and-tabs-menu/arc-reference/screenshots/switcher-across-spaces.jpg new file mode 100644 index 0000000..3ecdd6e Binary files /dev/null and b/openspec/changes/add-tab-switcher-and-tabs-menu/arc-reference/screenshots/switcher-across-spaces.jpg differ diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/arc-reference/screenshots/switcher-whole-panel.jpg b/openspec/changes/add-tab-switcher-and-tabs-menu/arc-reference/screenshots/switcher-whole-panel.jpg new file mode 100644 index 0000000..500958e Binary files /dev/null and b/openspec/changes/add-tab-switcher-and-tabs-menu/arc-reference/screenshots/switcher-whole-panel.jpg differ diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/design.md b/openspec/changes/add-tab-switcher-and-tabs-menu/design.md new file mode 100644 index 0000000..9335dd2 --- /dev/null +++ b/openspec/changes/add-tab-switcher-and-tabs-menu/design.md @@ -0,0 +1,173 @@ +# Design + +## Context + +- **Ctrl+Tab today** is the key equivalent of Chromium's Tab › Select Next Tab (`IDC_CYCLE_TO_NEXT_TAB`, from `accelerators_cocoa.mm`). `ClairBrowserWindow::ExecuteTabCommand` runs it over the sidebar's rows. Chromium's own shortcut table (`global_keyboard_shortcuts_mac.mm`) has no Ctrl+Tab entry, so the menu is the only route. +- **Chromium's Tab menu** (`IDC_TAB_MENU`, title "Tab") holds Chromium's items. `PinsMenu` hides Chromium's pin items and adds Clair's (Pin Tab, New Folder…, Back to Pinned URL, Close and Keep Pinned, Clear Today), and `SplitMenu` adds Split with Tab ›. `AppController` looks the menu up by tag on every main-window change: its `TabMenuBridge` appends the open tabs, and the vertical-tab code checks its items. +- **Context menus** come from `PinsLogic.todayMenu`, `pinnedMenu` and `favoriteMenu` as lists of items, with `nil` for a divider, grown one item at a time. +- **Pages of background tabs** have no surface to copy. Chromium's `ThumbnailTabHelper` captures a tab as it's hidden, but only with `kTabHoverCardImages`, which is off on macOS. Clair already copies a visible page for the still (`ClairBrowserWindow::CopyPage`). +- **Arc's switcher** was probed on 2026-11-26 (`arc-reference/README.md`). + +## Goals / Non-Goals + +**Goals:** +- Arc's Ctrl+Tab switcher: keys, contents, layout and the absence of animation. +- The owner's Tabs menu and context menu layouts, with Chromium's Tab menu and every Clair customization of it gone. + +**Non-Goals:** +- A setting for the old Ctrl+Tab. +- Arc's other menus. + +## Decisions + +### D1. Recents live in ClairUI, one list per window + +`BrowserWindowController` keeps a `RecentTabs` value: entry IDs, most recent first, with no cap (it only ever holds tabs that are open, and the panel shows the first five), where an entry is the row's tab ID. A split counts once, through its leading pane, as `RowOf` does. A Peek counts as its parent. On `activeTabDidChange`, the shown row moves to the front. The still's placeholder tab never enters the list. + +On every `tabsDidChange` and pins change, an entry whose tab no longer exists is dropped, in any Space or favorites. A closed page, a closed tab and a tab of a removed Space all go this way. On a profile swap (`shownSpaceDidChange(…swappedInFor:)`), the incoming window takes the outgoing window's list, as it takes its sidebar. The list belongs to the window as the user sees it. + +`RecentTabs` is pure logic, unit-tested with `FakeHost`, which reports tabs of every Space. + +Kept in the engine instead, the list would need a new observer call for something ClairUI already sees in full. + +### D2. The keys: a local event monitor + +`TabSwitcher` installs one `NSEvent` local monitor for `.keyDown` and `.flagsChanged`. It handles events only while the key window is a normal browser window with no Clair dialog or sheet up: + +| Event | Effect | +|---|---| +| Ctrl+Tab or Ctrl+Shift+Tab, with no other modifier | Opens the switcher with the second card selected (Shift: the last). With fewer than two entries, swallowed and nothing happens. | +| Tab or Shift+Tab, switcher open | Steps the selection, wrapping. | +| Esc, switcher open | Cancels. | +| Other keys, switcher open | Swallowed. | +| `flagsChanged` without Control, switcher open | Commits. | + +Every handled event returns nil, so the page, the command bar and Chromium never see it. The window resigning key or the shown tab closing cancels. A second monitor, active only while the panel shows, takes a left mouse down over a card, Control held, and commits that card, before AppKit can treat the Control-click as a secondary click. It takes no other mouse event. Arc lets a click choose a card too (the owner checked by hand). + +With Chromium's Tab menu deleted (D5), Chromium no longer has Ctrl+Tab at all. + +The open/step/commit/cancel state is a pure `SwitcherState` with unit tests. The monitor is thin glue. + +### D3. The panel + +A borderless, non-activating `NSPanel`, a child window of the browser window, hosting SwiftUI. It is laid out from Arc's measurements: + +- **Panel:** 27 pt padding, cards 157.5 × 105 pt with a 24 pt pitch gap, label row below each card. About 938 × 189 pt for five cards. Light background (`windowBackgroundColor` at Arc's #F2F2F2 in light mode), about 22 pt corner radius, hairline border and shadow. +- **Selection:** a 12 pt inset rounded highlight, about 12 pt radius, in the accent colour at the sidebar's selection opacity. The selected title is in the primary colour, the others secondary. +- **Labels:** favicon 16 pt, then the title or custom name at the sidebar's title size, medium weight, one line, with an ellipsis. +- **Position:** centred on the window, then moved inside the screen's visible frame. Arc centred a two-card panel on the window, but its five-card panel sat about 29 pt right of centre in a 963 pt window; centring is the simpler rule. + +Shown with `orderFront` and no animation, 100 ms after Ctrl+Tab (a timer `SwitcherState` starts on opening), or at once on a second Tab or Shift+Tab. A commit before the timer fires never shows the panel, so a quick Ctrl+Tab just switches, as in Arc, whose delay measured between 90 and 130 ms. The panel is re-rendered in place as the selection moves. Previews arriving late replace the placeholder in place. Dark mode uses the system's dark window background. Arc wasn't probed in dark mode. + +### D4. Page previews from the engine + +The contract (`ClairHost.h`, `ClairBrowser`): + +```objc +// A preview of the tab's page for the tab switcher, `size` in points. The +// shown tab's page as it is now; any other tab's as it was when this or +// another window last hid it; nil when there is none (never shown, crashed, +// or a copy that failed). `completion` runs once, on the main thread. +- (void)requestPreviewOfTab:(ClairTabID)tabID + size:(NSSize)size + completion:(void (^)(NSImage *_Nullable preview))completion; +``` + +- **Capture.** The engine copies a tab's page with `CopyPage` as the tab stops being shown. That happens in `ClairBrowserWindow`'s active-tab change, before Chromium hides it, which is where `TabStripModel` asks `ThumbnailTabHelper` for its own. The copy is scaled to 2× the card's width, cut to the card's 3:2 shape from the top, and kept on the tab as `WebContents` user data (`ClairTabPreview`). +- **Lifetime and memory.** One image per tab, replaced on each hide, freed with the tab: about 100 KB each. +- **The shown tab** is copied live on request. +- **Peeks.** A tab with a Peek gets the parent's page; the still's convention is followed. + +Turning on `kTabHoverCardImages` was rejected: it needs a patch to a Chromium default, and brings JPEG compression and background video capture that Clair doesn't need. + +A split's card asks for both panes and draws them side by side in pane order. + +### D5. Delete Chromium's Tab menu, add Clair's Tabs menu + +The engine deletes Chromium's Tab menu (the main menu item tagged `IDC_TAB_MENU`) in `clair_window_hooks.mm`, where it already reworks the main menu at start-up, before any window becomes main. ClairUI's new `TabsMenu` inserts its "Tabs" menu before the Window menu (`IDC_WINDOW_MENU`), where Chromium's sat. + +This needs no patch to a Chromium file. Nothing else breaks either: `AppController` finds the menu by tag on each main-window change, and with nil, `TabMenuBridge` and `onVerticalTabStripModeChanged` do nothing (every call is a nil message, and the latter returns early). + +Deleting beats hiding. A hidden item still fires its key equivalent (as `clair_window_hooks.mm` notes), so hiding would also mean clearing every key equivalent and leaving `TabMenuBridge` to fill a menu nobody sees. Deleting takes Ctrl+Tab, Ctrl+Shift+Tab and Search Tabs' shortcut away from Chromium with the menu. + +The items: + +| Item | Action | Enabled | +|---|---|---| +| Pin Tab / Unpin Tab ⌘D | `PinsLogic.MainMenuCommand.togglePin` | as today | +| Pin to Favorites | new `.pinToFavorites` → `favorite(tab:at:)` at the end | Today or pinned tab, not private | +| New Folder… | `.newFolder` | as today | +| Next Tab ⌥⌘↓, Previous Tab ⌥⌘↑ | `commandDispatch:` with `IDC_SELECT_NEXT_TAB` / `IDC_SELECT_PREVIOUS_TAB`, target nil | validated by Chromium. Chromium's shortcut table handles the keys first (`space-shortcuts.patch`), so the menu only shows them. | +| Split with Tab › | moved from `SplitMenu` | as today | +| Move to Space › | `move(tab:toSpace:)` on the shown row | other Spaces exist, not a favorite, not private | +| Clear Unpinned Tabs ⇧⌘K | `.clearToday` | as today | + +- **Moves out of other menus:** `PinsMenu` keeps only View › Collapse Pinned Tabs. `SplitMenu` keeps only its View items. +- **Removed:** `MainMenuCommand.backToPinnedURL` and `.closeKeepingPin`. Their row and keyboard routes stay. +- **Tags:** `TabsMenu` takes the tag range `0x436C_5200`. + +### D5a. Remove every customization of Chromium's Tab menu + +With Chromium's Tab menu deleted, nothing Clair did to it or for it is needed. Each was checked against Chromium's `main_menu_builder.mm`, `accelerators_cocoa.mm` (which only sets menu key equivalents) and `global_keyboard_shortcuts_mac.mm`: each command below is reachable only through that menu. + +**ClairUI** + +| Where | Goes | +|---|---| +| `PinsMenu.install` | Hiding Chromium's Pin Tab items (`IDC_WINDOW_PIN_TAB` 35013, `IDC_PIN_TARGET_TAB` 35051) and clearing their key equivalents. Inserting Pin Tab, New Folder…, Back to Pinned URL, Close and Keep Pinned and Clear Today into the Tab menu. `tabMenuTag` goes too. `PinsMenu` keeps only View › Collapse Pinned Tabs. | +| `SplitMenu.install` | Inserting Split with Tab › into the Tab menu. The item moves to `TabsMenu`. | +| `SplitTests`, `FoldersTests` (unit) | Their fake "Tab" menus. They test `TabsMenu` instead. | +| Runtime `PinsTests.tabMenu` | `menuBarItems["Tab"]` becomes "Tabs". Clear Today becomes Clear Unpinned Tabs. Back to Pinned URL moves to the row's icon or Edit Pinned Page ›. `FoldersTests` and `SplitViewTests` follow through `tabMenuItem`. | + +**Engine (`engine/overlay`)** + +| Where | Goes | +|---|---| +| `clair_window_hooks.mm` | Gains the deletion of the Tab menu (D5). | +| `ClairBrowserWindow::ExecuteTabCommand` | `IDC_CYCLE_TO_NEXT_TAB` and `IDC_CYCLE_TO_PREV_TAB` (Tab › Select Next/Previous Tab, Ctrl+Tab). `IDC_WINDOW_CLOSE_TABS_TO_RIGHT` (Close Tabs to the Right) and `IDC_WINDOW_CLOSE_OTHER_TABS` (Close Other Tabs). Close Tabs Below stays, through `-closeTabsBelowTab:`. `IDC_SELECT_NEXT_TAB` and `IDC_SELECT_PREVIOUS_TAB` stay for Opt+Cmd+Down and Up and for Tabs › Next and Previous Tab. | +| `ClairPeeks::ExecuteCommand` | `IDC_DUPLICATE_TAB` and `IDC_MOVE_TAB_TO_NEW_WINDOW` (Tab › Duplicate Tab and Move Tab to New Window). | +| `ClairWindowCommandHandler` validation | `IDC_DUPLICATE_TAB`, `IDC_MOVE_TAB_TO_NEW_WINDOW`, `IDC_WINDOW_CLOSE_OTHER_TABS` and `IDC_WINDOW_CLOSE_TABS_TO_RIGHT` in the modal-dialog list. | +| `ClairIsRemovedCommand` | `IDC_TAB_SEARCH`, `IDC_WINDOW_GROUP_TAB`, `IDC_GROUP_TARGET_TAB` and `IDC_NEW_SPLIT_TAB`, which it listed only to hide the Tab menu's items. With the menu gone, nothing sends them. Its other entries live in other menus and stay. | + +**Docs:** `docs/native-window.md`'s "Rows and commands" stops listing Ctrl+Tab among the row commands. + +Before deleting each engine case, the implementation greps the Chromium tree for other senders of the command (extension APIs, context menus Clair shows). A command with another sender keeps its case. + +### D6. Context menus in groups + +`PinsLogic` builds each menu as groups (`[[MenuItem]]`), and a helper joins non-empty groups with dividers. A group left empty (no pin items in private windows, no Close Tab on a closed pin) drops out with its divider. + +| Menu | Groups | +|---|---| +| Today | [Pin Tab, Pin to Favorites] · [Copy Link, Duplicate] · [Split with Tab ›, Move to Space ›] · [Rename…, Mute] · [Close Tab, Close Tabs Below] | +| Pinned | [Unpin Tab, Pin to Favorites] · [Copy Link, Duplicate] · [Split with Tab ›, Move to Space ›] · [Rename…, Mute, Edit Pinned Page ›] · [Close Tab when open] | +| Favorite | [Remove Favorite] · [Copy Link, Duplicate] · [Split with Tab ›] · [Rename…, Mute, Edit Pinned Page ›] · [Close Tab when shown] | +| Split chip | its kind's menu, Separate Tabs in Split with Tab's place, no Edit Pinned Page | + +- **Pinned Close Tab** runs Close and Keep Pinned on that pin. +- **Edit Pinned Page ›** gains Back to Pinned URL first (a new `MenuCommand.backToPinnedURL`), so a favorite navigated away keeps a way back now the Tabs menu item is gone. Favorites have no icon button. + +### D7. Runtime identifiers + +- **Panel:** `clair.tabSwitcher`. +- **Cards:** `clair.tabSwitcherCard`, with the title as the label, and the selected one with the selected trait. +- **Menu:** the menu bar item is titled "Tabs". + +### D8. The probe gets real key events + +`tests/probe/tools/keys.swift`, from this change's scratch tool, posts real key events with modifiers held across steps (`ctrldown tab sleep:0.5 shot:… ctrlup`), which XCUITest's `typeKey` can't do. Arc took them. The README gains it beside `drag` and `mouse`. + +## Risks / Trade-offs + +- **[A hide copy can miss]** If the surface is gone before `CopyFromSurface` answers, the tab keeps its older preview or none. → Fall back to a blank card with the favicon (spec), and check timing in the hand check. +- **[The local monitor sees every key]** → It returns early unless Control is down or the switcher is open, so the cost per key is one flag test. +- **[A later Chromium looks the Tab menu up without a nil check]** → The engine-update patch check won't catch it, but the runtime suite's window activation would crash. Grep for `IDC_TAB_MENU` on each engine update (a note in `docs/building.md`'s "Updating the engine"). +- **[Arc's horizontal position]** Arc's panel wasn't centred on the probe window. → Centred and kept on screen. Revisit if the owner sees a difference. + +## Migration Plan + +None: Clair isn't released. The engine key changes with `ClairHost.h`, so the engine is rebuilt. + +## Open Questions + +None. diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/proposal.md b/openspec/changes/add-tab-switcher-and-tabs-menu/proposal.md new file mode 100644 index 0000000..7f031bf --- /dev/null +++ b/openspec/changes/add-tab-switcher-and-tabs-menu/proposal.md @@ -0,0 +1,67 @@ +# Proposal + +## Why + +In Clair, Ctrl+Tab still steps through the sidebar's rows in order, as Chromium's Next Tab does. In Arc it goes back to the tab used last, with a switcher showing the five most recent tabs while Ctrl is held. People coming from Arc expect Ctrl+Tab to return to the previous tab. The menu bar's Tab menu is also still Chromium's: it is called "Tab", mixes Chromium items that mean nothing in Clair (Move Tab to New Window, Search Tabs, Close Tabs to the Right…) with Clair's own items, and its tab context menus have grown one item at a time with no sections. The owner gave the target layouts for both. + +## What Changes + +- **Ctrl+Tab switcher, as in Arc** (probed on 2026-11-26, `arc-reference/`): + - Pressing Ctrl+Tab shows a panel over the window with the window's five most recently used tabs, the shown tab first. Each tab is a card with a preview of its page, its favicon and its title. The second card is selected. + - While Ctrl is held, each Tab selects the next card and each Shift+Tab the previous one, wrapping at the ends. Ctrl+Shift+Tab opens the panel with the last card selected. + - Releasing Ctrl shows the selected tab, clicking a card shows that card's tab, and Esc closes the panel without switching. A quick Ctrl+Tab returns to the previous tab without showing the panel: as in Arc, it appears only once Ctrl has been held for about 100 ms, or at once on a second Tab. + - Recents span the window's Spaces, as in Arc, and include favorites and pinned tabs while their page is open. Choosing a tab of another Space switches the window to that Space. A split is one card showing both pages, labelled with both favicons. A tab leaves the list when its page closes. + - The panel appears, moves its selection and closes with no animation, as in Arc. + - Opt+Cmd+Down and Up (Next Tab and Previous Tab) and Cmd+1 to 9 still step through the sidebar's rows. +- **Clair's Tabs menu replaces Chromium's Tab menu,** which is deleted. It lists, in sections: + - Pin Tab (⌘D), Pin to Favorites and New Folder… + - Next Tab (⌥⌘↓) and Previous Tab (⌥⌘↑) + - Split with Tab › and Move to Space › + - Clear Unpinned Tabs (⇧⌘K) + + Chromium's items leave the menu bar. Clair's Back to Pinned URL and Close and Keep Pinned leave it too: they stay on the row's icon, the − button and Cmd+W. +- **Tab context menus in sections.** A Today tab's menu becomes: + - Pin Tab and Pin to Favorites + - Copy Link and Duplicate + - Split with Tab › and Move to Space › + - Rename… and Mute or Unmute + - Close Tab and Close Tabs Below + + Pinned tabs and favorites get the same sections and order with their own items: Unpin Tab and Remove Favorite in place of the pin items, and Edit Pinned Page › kept. The split row's menu keeps Separate Tabs in place of Split with Tab ›. +- **BREAKING (`ClairHost.h`):** the browser gains page previews for tabs and a call that shows a tab in any of the window's Spaces. + +**Out of scope:** +- Arc's other menu bar menus, and View, File and Edit, which keep their items. +- A setting to turn the switcher off or make Ctrl+Tab step through the sidebar. + +## Capabilities + +### New Capabilities + +- `tab-switcher`: Ctrl+Tab's switcher: the recents list and what it holds, the panel, its cards and previews, the keys, and choosing a tab. +- `tabs-menu`: the menu bar's Tabs menu: its items, their order, shortcuts and when each is enabled, and Chromium's Tab menu leaving the menu bar. + +### Modified Capabilities + +- `sidebar`: "Today tab menu" takes the new sections and order. +- `pinned-tabs`: + - "Pinned tab menu" takes the new sections. + - "Closing a pinned tab keeps it pinned" and "Navigated away from the pinned URL" lose their Tabs menu items. + - "Clear Today" is renamed Clear Unpinned Tabs in the Tabs menu, and the sidebar's Clear button's tooltip reads "Clear unpinned tabs". + - "Editing the pinned URL" adds Back to Pinned URL to Edit Pinned Page ›, so a favorite navigated away still has it. + - "No pins in private windows" drops the removed items. +- `favorites`: + - "Favorite menu" takes the new sections. + - "Leaving a favorite's site" points to Edit Pinned Page › Back to Pinned URL instead of the Tabs menu. +- `spaces`: "Tab commands follow the Space" no longer covers Ctrl+Tab, which follows `tab-switcher`. +- `peek`: "Tab shortcuts treat a tab and its Peek as one" covers the switcher, and names Next and Previous Tab's current shortcuts. +- `split-view`: + - "Tab commands treat a split as one row" covers the switcher. + - "The split row's menu" places Separate Tabs in its section. + +## Impact + +- **`native/ClairHost.h`** changes, so the engine key changes and the engine is rebuilt. +- **Engine:** the engine copies a tab's page as it stops being shown, as it copies the still, and keeps one preview per tab. A new browser call shows a tab in another of the window's Spaces. Chromium's Tab menu is deleted at start-up, and Clair's handling of commands only it sent goes: Select Next/Previous Tab, Close Tabs to the Right, Close Other Tabs, Duplicate Tab and Move Tab to New Window for Peeks, and the hiding of its Search Tabs, Group and Split items. +- **ClairUI:** a recents list per window, the switcher panel, a key monitor for Ctrl+Tab, `TabsMenu` in place of every customization of Chromium's Tab menu (`PinsMenu` hiding Chromium's pin items and adding Clair's, `SplitMenu` adding Split with Tab), and the context menus in `PinsLogic`. +- **Tests:** ClairUI unit tests for recents, the switcher's keys and the menus. The runtime suite's checks of the Tab menu and the context menus change with them. diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/specs/favorites/spec.md b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/favorites/spec.md new file mode 100644 index 0000000..e7ea75b --- /dev/null +++ b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/favorites/spec.md @@ -0,0 +1,31 @@ +## MODIFIED Requirements + +### Requirement: Favorite menu +A favorite's context menu SHALL offer, with a divider between each group: Remove Favorite; Copy Link and Duplicate; Split with Tab › (`split-view`); Rename…, Mute or Unmute, and Edit Pinned Page › (`pinned-tabs`); Close Tab while its page is shown. Hovering a tile SHALL show no button. + +#### Scenario: The shown favorite's menu +- **WHEN** the window shows "Mail" and the user right-clicks its tile +- **THEN** the menu offers Remove Favorite, a divider, Copy Link, Duplicate, a divider, Split with Tab, a divider, Rename…, Mute, Edit Pinned Page, a divider and Close Tab + +#### Scenario: A favorite that isn't shown +- **WHEN** the window shows another tab and the user right-clicks the tile of "Mail" +- **THEN** the menu ends with Edit Pinned Page, with no Close Tab + +### Requirement: Leaving a favorite's site +From a favorite, a URL the user enters in the command bar or URL field that is on another site (another scheme or host, as for Peeks in `peek`) SHALL open in a new Today tab at the top, leaving the favorite's page as it was. A URL on the same site SHALL load in the favorite. A favorite's page in a split (`split-view`) SHALL load either in its pane. Its menu's Edit Pinned Page › offers Back to Pinned URL (`pinned-tabs`), except in a favorited split (`split-view`). + +#### Scenario: Another site from the URL field +- **WHEN** the window shows the favorite "Mail" at `https://mail.example.com/` and the user enters `https://news.example.org/` in the URL field +- **THEN** a new Today tab at the top shows `https://news.example.org/`, and "Mail" keeps its page + +#### Scenario: The same site +- **WHEN** the user enters `https://mail.example.com/settings` there instead +- **THEN** "Mail" loads it + +#### Scenario: Another site in a favorited split's pane +- **WHEN** the window shows a favorited split of "Mail" and "Calendar", with "Mail" focused, and the user enters `https://news.example.org/` in the command bar +- **THEN** "Mail"'s pane loads `https://news.example.org/`, and no Today tab opens + +#### Scenario: A favorited split navigated away +- **WHEN** a favorited split's "Mail" pane follows a link to another page on its site, and the user right-clicks its chip +- **THEN** the menu has no Edit Pinned Page and no Back to Pinned URL diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/specs/peek/spec.md b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/peek/spec.md new file mode 100644 index 0000000..6e7d77b --- /dev/null +++ b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/peek/spec.md @@ -0,0 +1,20 @@ +## MODIFIED Requirements + +### Requirement: Tab shortcuts treat a tab and its Peek as one +Ctrl+Tab and Ctrl+Shift+Tab (`tab-switcher`), Opt+Cmd+Down and Up, and Cmd+1 to Cmd+9 SHALL count a tab and its Peek as one stop. Selecting a tab that has a Peek SHALL show the Peek. + +#### Scenario: Ctrl+Tab across a Peek +- **WHEN** the window showed "Docs", then "Mail" with its Peek open, and the user presses Ctrl+Tab +- **THEN** the switcher has one card for "Mail" and its Peek, and releasing Ctrl shows "Docs" while the Peek of "Mail" stays open + +#### Scenario: Back to a Peek +- **WHEN** the user then presses Ctrl+Tab again +- **THEN** the window shows "Mail" with its Peek + +#### Scenario: Next Tab across a Peek +- **WHEN** the first of three tabs has a Peek open and shows it, and the user presses Opt+Cmd+Down +- **THEN** the second tab becomes active, and the first tab's Peek stays open + +#### Scenario: Cmd+number +- **WHEN** the second tab has a Peek and the user presses Cmd+2 +- **THEN** the second tab shows with its Peek diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/specs/pinned-tabs/spec.md b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/pinned-tabs/spec.md new file mode 100644 index 0000000..3e28bb4 --- /dev/null +++ b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/pinned-tabs/spec.md @@ -0,0 +1,107 @@ +## MODIFIED Requirements + +### Requirement: Pinned tab menu +A pinned tab's context menu SHALL offer, with a divider between each group: Unpin Tab and Pin to Favorites; Copy Link and Duplicate; Split with Tab › (`split-view`) and Move to Space (with more than one Space); Rename…, Mute or Unmute, and Edit Pinned Page ›; Close Tab while its page is open. It SHALL offer no Remove Pin. Copy Link SHALL copy the page's current URL, or the pinned URL while the page is closed. Duplicate SHALL open the same URL as a new Today tab at the top. + +#### Scenario: Copy Link on a closed pinned tab +- **WHEN** the pinned tab "Mail" has no open page and the user chooses Copy Link +- **THEN** its pinned URL is copied + +#### Scenario: Duplicate +- **WHEN** the user chooses Duplicate on the pinned tab "Docs" +- **THEN** a new Today tab at the top of the list shows the same URL, and "Docs" stays pinned + +#### Scenario: The menu's items +- **WHEN** there is one Space and the user right-clicks the pinned tab "Mail", whose page is open +- **THEN** the menu offers Unpin Tab, Pin to Favorites, a divider, Copy Link, Duplicate, a divider, Split with Tab, a divider, Rename…, Mute, Edit Pinned Page, a divider and Close Tab + +#### Scenario: The menu's last items +- **WHEN** the user right-clicks a pinned tab whose page is open +- **THEN** the menu ends with Close Tab, after a divider + +#### Scenario: A closed pinned tab +- **WHEN** the user right-clicks a pinned tab whose page isn't open +- **THEN** the menu has no Close Tab and no divider before where it would be, and Mute is disabled + +#### Scenario: Split with Tab +- **WHEN** the user right-clicks the pinned tab "Mail" and chooses Split with Tab › "News" +- **THEN** the window shows a split of "Mail" and "News", "News" focused + +### Requirement: Closing a pinned tab keeps it pinned +On the selected pinned tab, hovering its row SHALL show a − button with the tooltip "Close and Keep Pinned" and Cmd+W. The button, Cmd+W and Close Tab in its menu SHALL close its page and keep the row where it is. The window SHALL then show the next tab as `spaces` defines. + +#### Scenario: Close and Keep Pinned +- **WHEN** the user selects the pinned tab "Mail" from the Today tab "News", and presses Cmd+W +- **THEN** "Mail" keeps its row, its page is closed, and "News" is active + +#### Scenario: Selecting it again +- **WHEN** the user then clicks "Mail" +- **THEN** its pinned URL loads again + +#### Scenario: From its menu +- **WHEN** the user right-clicks the open pinned tab "Docs", which isn't shown, and chooses Close Tab +- **THEN** its page closes, its row stays, and the window keeps its tab + +### Requirement: Navigated away from the pinned URL +While a pinned tab's page is at another URL than its pinned URL, its row SHALL show its icon, a grey "/" and the current page's title, or its custom name. Hovering the icon SHALL turn it into a button and show "Back to Pinned URL" under the title. Clicking it SHALL load the pinned URL as a new navigation. As in Arc, another query or fragment, or a redirect from the pinned URL, is still at it. + +#### Scenario: Following a link +- **WHEN** the pinned tab "Docs" at `https://docs.example.com/` follows a link to `https://docs.example.com/guide` titled "Guide" +- **THEN** its row reads "/ Guide" after its icon + +#### Scenario: Back to Pinned URL +- **WHEN** the user then clicks the row's icon +- **THEN** the tab loads `https://docs.example.com/`, the row shows its plain title again, and Back returns to "Guide" + +#### Scenario: Another query +- **WHEN** the pinned tab at `https://docs.example.com/search?q=a` follows a link to `https://docs.example.com/search?q=b` +- **THEN** its row shows its plain title, with no "/" + +#### Scenario: At the pinned URL +- **WHEN** the pinned tab is at its pinned URL and the user hovers its icon +- **THEN** the icon isn't a button and no "Back to Pinned URL" shows + +### Requirement: Clear Today +While the pointer is over the sidebar and the Space has Today tabs, the divider SHALL show "↓ Clear" at its trailing end, with the tooltip "Clear unpinned tabs" and Shift+Cmd+K. It and Tabs › Clear Unpinned Tabs (Shift+Cmd+K, `tabs-menu`) SHALL close every Today tab of the Space, each with its leave-page confirmation, and leave pinned tabs and favorites as they are. + +#### Scenario: Clearing +- **WHEN** "Work" has two pinned tabs and three Today tabs, and the user clicks Clear +- **THEN** the three Today tabs close, and the two pinned tabs stay + +#### Scenario: Restoring +- **WHEN** the user then chooses Restore Last Closed Tab +- **THEN** the last Today tab closed comes back + +#### Scenario: No Today tabs +- **WHEN** the Space has no Today tabs +- **THEN** there is no divider and no Clear button, and Tabs › Clear Unpinned Tabs is disabled + +### Requirement: No pins in private windows +Incognito and guest windows SHALL show no pinned section or favorites, and SHALL disable Pin Tab, Pin to Favorites, New Folder… and Collapse Pinned Tabs. Their tabs' menus SHALL offer neither pin item. + +#### Scenario: Incognito +- **WHEN** the user opens an incognito window and presses Cmd+D +- **THEN** nothing is pinned, and the sidebar has no pinned section or favorites + +### Requirement: Editing the pinned URL +A pinned tab's menu SHALL offer Edit Pinned Page › with "Back to Pinned URL", enabled while the page is at another URL than its pinned URL and loading the pinned URL as the row's icon does, "Replace Pinned URL with Current", which makes the page's current URL the pinned URL, and "Edit…", which opens a dialog titled "Edit Pinned URL" with the URL selected in a field, Cancel and Save. Save SHALL be disabled while the field holds no valid URL. + +#### Scenario: Replacing with the current URL +- **WHEN** the pinned tab "Docs" shows `https://docs.example.com/guide` and the user chooses Replace Pinned URL with Current +- **THEN** its pinned URL is `https://docs.example.com/guide`, and its row no longer shows "/" + +#### Scenario: Editing +- **WHEN** the user chooses Edit…, types `https://docs.example.com/api` and clicks Save +- **THEN** that is the pinned URL, and Back to Pinned URL loads it + +#### Scenario: Not a URL +- **WHEN** the field holds "not a url" +- **THEN** Save is disabled + +#### Scenario: Back to Pinned URL from the menu +- **WHEN** the favorite "Docs" at `https://docs.example.com/` follows a link to `https://docs.example.com/guide`, and the user chooses Edit Pinned Page › Back to Pinned URL on its tile +- **THEN** it loads `https://docs.example.com/` + +#### Scenario: At the pinned URL +- **WHEN** the pinned tab is at its pinned URL +- **THEN** Edit Pinned Page › Back to Pinned URL is disabled diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/specs/sidebar/spec.md b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/sidebar/spec.md new file mode 100644 index 0000000..3cbd0ca --- /dev/null +++ b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/sidebar/spec.md @@ -0,0 +1,20 @@ +## MODIFIED Requirements + +### Requirement: Today tab menu +A Today tab's context menu SHALL offer, with a divider between each group: Pin Tab and Pin to Favorites; Copy Link and Duplicate; Split with Tab › (`split-view`) and Move to Space › (`spaces`); Rename… and Mute or Unmute; Close Tab and Close Tabs Below. A group whose items are all left out SHALL be left out with its divider. Close Tabs Below SHALL close only the Today tabs below it. + +#### Scenario: Today tab's menu +- **WHEN** there is one Space and the user right-clicks a Today tab's row +- **THEN** the menu offers Pin Tab, Pin to Favorites, a divider, Copy Link, Duplicate, a divider, Split with Tab, a divider, Rename…, Mute, a divider, Close Tab and Close Tabs Below + +#### Scenario: With another Space +- **WHEN** there are two Spaces and the user right-clicks a Today tab's row +- **THEN** Move to Space follows Split with Tab in its group + +#### Scenario: Incognito +- **WHEN** the user right-clicks a tab's row in an incognito window +- **THEN** the menu starts with Copy Link and Duplicate, with no pin items and no divider before them + +#### Scenario: Close Tabs Below leaves pinned tabs +- **WHEN** the user chooses Close Tabs Below on the first Today tab of a Space with pinned tabs +- **THEN** the Today tabs below it close, and the pinned tabs stay diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/specs/spaces/spec.md b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/spaces/spec.md new file mode 100644 index 0000000..19a7099 --- /dev/null +++ b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/spaces/spec.md @@ -0,0 +1,29 @@ +## MODIFIED Requirements + +### Requirement: Tab commands follow the Space +Tabs › Next Tab (Opt+Cmd+Down), Previous Tab (Opt+Cmd+Up), Cmd+1 to Cmd+9 and Close Tabs Below SHALL act on the rows the sidebar lists, pinned tabs first and then Today tabs, in its order, whichever window holds them, and never on a tab of another Space or on favorites. Selecting a pinned tab whose page isn't open SHALL open it. Ctrl+Shift+PageDown and Ctrl+Shift+PageUp SHALL move the active row one row down or up within its section, stopping at its ends. Ctrl+Tab follows `tab-switcher`. + +#### Scenario: Moving a row with the keyboard +- **WHEN** a window shows "Work", whose rows are X, Y and Z, Z is active, and the user presses Ctrl+Shift+PageUp +- **THEN** the rows are X, Z and Y, and Z is still active + +#### Scenario: Cmd+number +- **WHEN** a window shows "Work", whose rows are X, Y and Z, and the user presses Cmd+2 +- **THEN** Y is active + +#### Scenario: Next tab at the Space's end +- **WHEN** the last row of the Space is active and the user presses Opt+Cmd+Down +- **THEN** the first row of the same Space is active + +#### Scenario: Cmd+number on a tab from another window +- **WHEN** a window shows "Work", whose rows are X, Y and Z, Y was opened in another window, and the user presses Cmd+2 +- **THEN** this window shows Y + +#### Scenario: Cmd+number with pinned tabs and favorites +- **WHEN** the profile has three favorites, "Work" has the pinned tabs P and Q, Q isn't open, and the Today tabs X and Y, and the user presses Cmd+2 +- **THEN** Q opens at its pinned URL and is active + +#### Scenario: Moving a row stops at its section +- **WHEN** the first Today tab is active and the user presses Ctrl+Shift+PageUp +- **THEN** nothing moves, and the tab stays unpinned + diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/specs/split-view/spec.md b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/split-view/spec.md new file mode 100644 index 0000000..b43300f --- /dev/null +++ b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/split-view/spec.md @@ -0,0 +1,23 @@ +## MODIFIED Requirements + +### Requirement: Tab commands treat a split as one row +The tab commands of `spaces` (Next Tab, Previous Tab, Cmd+1 to Cmd+9, Close Tabs Below, and Ctrl+Shift+PageDown and PageUp) SHALL count a split as one row, and the switcher (`tab-switcher`) SHALL count it as one tab. Selecting it SHALL show the split as clicking its row does. + +#### Scenario: Next Tab +- **WHEN** Today lists "Mail", a split, and "Docs", "Mail" is shown, and the user presses Opt+Cmd+Down twice +- **THEN** the window shows the split and then "Docs" + +#### Scenario: Ctrl+Tab +- **WHEN** the window showed a split and then "Docs", and the user presses Ctrl+Tab +- **THEN** the window shows the split, with the pane focused last focused + +### Requirement: The split row's menu +Right-clicking a split row SHALL open the menu of its kind for the tab whose chip is under the pointer (Today tab menu, `pinned-tabs`, `favorites`), without Back to Pinned URL or Edit Pinned Page ›, and with Separate Tabs in place of Split with Tab ›. Pin Tab, Pin to Favorites, Unpin Tab, Remove Favorite and Move to Space SHALL act on the whole split. + +#### Scenario: A Today split's menu +- **WHEN** the user right-clicks the "Docs" chip of a Today split +- **THEN** the menu offers the Today tab menu's items for "Docs", with Separate Tabs where Split with Tab would be + +#### Scenario: Copy Link +- **WHEN** the user chooses Copy Link from that menu +- **THEN** the URL of "Docs" is copied diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/specs/tab-switcher/spec.md b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/tab-switcher/spec.md new file mode 100644 index 0000000..a3cdb14 --- /dev/null +++ b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/tab-switcher/spec.md @@ -0,0 +1,146 @@ +## Purpose + +Ctrl+Tab's switcher returns to recently used tabs, as in Arc: while Ctrl is held, a panel shows the window's five most recent tabs with previews of their pages, and releasing Ctrl shows the one selected. + +## ADDED Requirements + +### Requirement: Recent tabs +Each browser window SHALL keep its tabs in the order it last showed them, most recent first, across its Spaces. Today tabs, pinned tabs and favorites SHALL count; a tab and its Peek SHALL be one entry, and so SHALL the two tabs of a split. A tab SHALL leave the list when its page closes. Choosing a tab another window holds SHALL take it, as clicking its row does (`spaces`). + +#### Scenario: Most recent first +- **WHEN** the window shows "Mail", then "News", then "Docs" +- **THEN** its recent tabs are "Docs", "News" and "Mail", in that order + +#### Scenario: Across Spaces +- **WHEN** the window shows "Mail" in "Work", then switches to "Home" and shows "Recipes" +- **THEN** its recent tabs are "Recipes" and then "Mail" + +#### Scenario: A pinned tab's page closes +- **WHEN** the recent tabs are "Docs", the pinned tab "Mail" and "News", and the user closes "Mail" with Close and Keep Pinned +- **THEN** the recent tabs are "Docs" and "News" + +#### Scenario: A favorite +- **WHEN** the window shows the favorite "Calendar" and then "Docs" +- **THEN** its recent tabs are "Docs" and then "Calendar" + +### Requirement: Opening the switcher +Ctrl+Tab SHALL open the switcher over the window: a panel with a card for each of the window's five most recent tabs, or fewer when it has fewer, the shown tab first. The second card SHALL be selected. Ctrl+Shift+Tab SHALL open it with the last card selected. With one recent tab or none, neither SHALL do anything. The switcher SHALL open in incognito and guest windows too. + +#### Scenario: Seven recent tabs +- **WHEN** the recent tabs are "BBC", "Example", "MDN", "Cat", "Hacker News", "GitHub" and "Apple", and the user presses Ctrl+Tab and keeps Ctrl held +- **THEN** the switcher shows "BBC", "Example", "MDN", "Cat" and "Hacker News", and "Example" is selected + +#### Scenario: Backwards +- **WHEN** the user presses Ctrl+Shift+Tab instead +- **THEN** "Hacker News" is selected + +#### Scenario: Two recent tabs +- **WHEN** the recent tabs are "Docs" and "Mail", and the user presses Ctrl+Tab and keeps Ctrl held +- **THEN** the switcher shows "Docs" and "Mail", and "Mail" is selected + +#### Scenario: One tab +- **WHEN** the window has shown only "Docs" and the user presses Ctrl+Tab +- **THEN** nothing happens + +### Requirement: Moving the selection +While the switcher is open, Tab SHALL select the next card and Shift+Tab the previous one, Ctrl still held, wrapping from the last card to the first and from the first to the last. Ctrl+Tab and Ctrl+Shift+Tab SHALL reach the switcher before the page or any field in the window. + +#### Scenario: Stepping +- **WHEN** the switcher shows five cards with the second selected, and the user presses Tab +- **THEN** the third card is selected + +#### Scenario: Wrapping +- **WHEN** the last card is selected and the user presses Tab +- **THEN** the first card, the shown tab, is selected + +#### Scenario: In a text field +- **WHEN** the focus is in a page's text area and the user presses Ctrl+Tab +- **THEN** the switcher opens, and the text area gets no keystroke + +### Requirement: Choosing a tab +Releasing Ctrl SHALL close the switcher and show the selected tab, as clicking its row or tile does, and a tab of another Space SHALL first switch the window to that Space. A quick Ctrl+Tab, released at once, SHALL therefore show the previous tab. Selecting the first card and releasing Ctrl SHALL leave the window as it is. + +#### Scenario: Releasing Ctrl +- **WHEN** the switcher has "MDN" selected and the user releases Ctrl +- **THEN** the switcher closes and the window shows "MDN" + +#### Scenario: A quick Ctrl+Tab +- **WHEN** the window shows "Docs", which it showed after "Mail", and the user presses and releases Ctrl+Tab +- **THEN** the window shows "Mail" + +#### Scenario: Another Space +- **WHEN** the window shows "Work", the switcher has "Recipes" of "Home" selected, and the user releases Ctrl +- **THEN** the window shows "Home" with "Recipes" active + +### Requirement: Cancelling the switcher +Esc SHALL close the switcher without switching tabs, even while Ctrl is still held. So SHALL the window losing key status and the shown tab closing. + +#### Scenario: Esc +- **WHEN** the switcher has "Example" selected and the user presses Esc, then releases Ctrl +- **THEN** the switcher closes and the window keeps showing the tab it showed + +#### Scenario: Switching apps +- **WHEN** the switcher is open and another app becomes active +- **THEN** the switcher closes and the window keeps its tab + +### Requirement: Choosing a card with the pointer +While the panel shows, clicking a card SHALL close the switcher and show that card's tab, as releasing Ctrl on it does, as in Arc. Ctrl is still held then, since releasing it closes the panel. + +#### Scenario: Clicking a card +- **WHEN** the switcher shows "BBC", "Example", "MDN", "Cat" and "Hacker News", "Example" is selected, and the user clicks "Cat" with Ctrl held +- **THEN** the switcher closes and the window shows "Cat", and releasing Ctrl then changes nothing + +### Requirement: A quick Ctrl+Tab shows no panel +The panel SHALL appear only once Ctrl has been held for 100 ms after Ctrl+Tab or Ctrl+Shift+Tab, or at once when Tab or Shift+Tab is pressed again within that time. Releasing Ctrl before the panel appears SHALL show the selected tab without the panel ever appearing. + +#### Scenario: A quick tap +- **WHEN** the window shows "Docs", which it showed after "Mail", and the user presses Ctrl+Tab and releases Ctrl within 100 ms +- **THEN** the window shows "Mail", and no panel appeared + +#### Scenario: Holding Ctrl +- **WHEN** the window has two or more recent tabs, and the user presses Ctrl+Tab, keeps Ctrl held and presses nothing else +- **THEN** the panel appears 100 ms after the press + +#### Scenario: Two quick Tabs +- **WHEN** the window has three or more recent tabs, and the user presses Ctrl+Tab and, within 100 ms, Tab again, Ctrl still held +- **THEN** the panel appears at once, with the third card selected + +### Requirement: Switcher panel +The panel SHALL lie over the window, centred on it and kept on its screen, and SHALL hold its cards in one row, from left to right, as Arc's does (`arc-reference/`): about 27 points of padding on each side, cards about 157 points wide with about 24 points between them, a light rounded panel with a shadow. It SHALL appear, move its selection and close with no animation. + +#### Scenario: Five cards +- **WHEN** the switcher shows five cards +- **THEN** the panel is about 938 by 189 points, centred on the window + +#### Scenario: No animation +- **WHEN** the user presses Ctrl+Tab +- **THEN** the panel shows at its full size and opacity in a single frame, 100 ms after the press + +### Requirement: Cards +Each card SHALL show a preview of its tab's page, about 157 by 105 points with rounded corners, filled from the page's top edge, and below it the tab's favicon and its title or custom name, on one line, cut short with an ellipsis. A split's card SHALL show both pages side by side, in pane order, and both favicons with no title. The selected card SHALL show a rounded highlight in the window's accent colour around its preview and label, and its title SHALL be darker. + +#### Scenario: A renamed tab +- **WHEN** the tab "Mail" has the custom name "Inbox" and its card shows +- **THEN** the card reads "Inbox" + +#### Scenario: A split +- **WHEN** the recent tabs include a split of "News" and "Docs" +- **THEN** one card shows both pages, "News" on the left, and the favicons of "News" and "Docs" below + +### Requirement: Page previews +A card's preview SHALL show the page as it was when the window last showed it, and the shown tab's card the page as it is. A tab with no preview yet SHALL show a blank card with its favicon in the middle. A crashed tab's card SHALL show a blank preview too. + +#### Scenario: A background tab +- **WHEN** the user scrolls "News" to its comments, shows "Docs", and presses Ctrl+Tab +- **THEN** the card of "News" shows its comments + +#### Scenario: No preview yet +- **WHEN** a tab restored at launch has never been shown and its card shows +- **THEN** the card shows a blank preview with the tab's favicon + +### Requirement: Recents and the other tab commands +Next Tab (Opt+Cmd+Down), Previous Tab (Opt+Cmd+Up) and Cmd+1 to Cmd+9 SHALL keep stepping through the sidebar's rows as `spaces` defines, and showing a tab with them SHALL make it the most recent. + +#### Scenario: Next Tab +- **WHEN** the window shows "Mail", the next row is "News", and the user presses Opt+Cmd+Down and then Ctrl+Tab +- **THEN** the window shows "News" and then "Mail" diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/specs/tabs-menu/spec.md b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/tabs-menu/spec.md new file mode 100644 index 0000000..db009b5 --- /dev/null +++ b/openspec/changes/add-tab-switcher-and-tabs-menu/specs/tabs-menu/spec.md @@ -0,0 +1,65 @@ +## Purpose + +The menu bar's Tabs menu holds Clair's commands for the shown tab and the Space's tabs, in place of Chromium's Tab menu, with the items and shortcuts the owner chose after Arc's. + +## ADDED Requirements + +### Requirement: Tabs menu items +The menu bar SHALL have a Tabs menu just before the Window menu, offering, with a divider between each group: +- Pin Tab (⌘D), Pin to Favorites and New Folder… +- Next Tab (⌥⌘↓) and Previous Tab (⌥⌘↑) +- Split with Tab › and Move to Space › +- Clear Unpinned Tabs (⇧⌘K) + +It SHALL offer nothing else. + +#### Scenario: The items +- **WHEN** the user opens the Tabs menu +- **THEN** it offers Pin Tab, Pin to Favorites, New Folder…, a divider, Next Tab, Previous Tab, a divider, Split with Tab, Move to Space, a divider and Clear Unpinned Tabs + +### Requirement: Chromium's Tab menu is gone +The menu bar SHALL have no Chromium Tab menu, and none of its items, such as Move Tab to New Window, Search Tabs or Close Tabs to the Right, SHALL appear elsewhere in it. Their shortcuts SHALL do nothing unless Clair gives them another meaning. + +#### Scenario: The menu bar +- **WHEN** the user looks at the menu bar of a browser window +- **THEN** it has a Tabs menu and no Tab menu + +### Requirement: Acting on the shown tab +The Tabs menu's items SHALL act on the main browser window and its shown tab, as `pinned-tabs`, `favorites`, `tab-folders`, `split-view` and `spaces` define for the same commands. Without a browser window, every item SHALL be disabled. + +#### Scenario: Pin Tab +- **WHEN** the window shows the Today tab "Mail" and the user chooses Tabs › Pin Tab +- **THEN** "Mail" becomes the last pinned tab, as Cmd+D does + +#### Scenario: No window +- **WHEN** no browser window is open and the user opens the Tabs menu +- **THEN** every item is disabled + +### Requirement: Pin items +Pin Tab SHALL read Unpin Tab on a pinned tab, and SHALL be disabled on a favorite. Pin to Favorites SHALL make the shown Today or pinned tab the last favorite, as Pin to Favorites in its menu does, and SHALL be disabled on a favorite. Both, and New Folder…, SHALL be disabled in incognito and guest windows. + +#### Scenario: On a pinned tab +- **WHEN** the window shows a pinned tab and the user opens the Tabs menu +- **THEN** the first item reads Unpin Tab, and Pin to Favorites is enabled + +#### Scenario: On a favorite +- **WHEN** the window shows a favorite +- **THEN** Pin Tab and Pin to Favorites are disabled + +### Requirement: Move to Space submenu +Tabs › Move to Space › SHALL list every Space but the shown one, in the switcher's order, each with its icon, and move the shown tab there as a tab's Move to Space does (`spaces`). It SHALL be disabled with one Space, on a favorite, and in incognito and guest windows. + +#### Scenario: Moving the shown tab +- **WHEN** the window shows "Docs" in "Home", and the user chooses Tabs › Move to Space › "Research" +- **THEN** the window shows "Research" with "Docs" first in its list and active + +#### Scenario: One Space +- **WHEN** there is one Space +- **THEN** Tabs › Move to Space is disabled + +### Requirement: Clear Unpinned Tabs +Tabs › Clear Unpinned Tabs (⇧⌘K) SHALL close the shown Space's Today tabs as the sidebar's Clear does (`pinned-tabs`), and SHALL be disabled while the Space has none. + +#### Scenario: Clearing +- **WHEN** "Work" has two pinned tabs and three Today tabs, and the user presses Shift+Cmd+K +- **THEN** the three Today tabs close, and the two pinned tabs stay diff --git a/openspec/changes/add-tab-switcher-and-tabs-menu/tasks.md b/openspec/changes/add-tab-switcher-and-tabs-menu/tasks.md new file mode 100644 index 0000000..67bb2b9 --- /dev/null +++ b/openspec/changes/add-tab-switcher-and-tabs-menu/tasks.md @@ -0,0 +1,109 @@ +# Tasks + +Groups 1 and 2 change the engine key, so build the engine first and push docs afterwards, as `CLAUDE.md` describes. "CI" is the merge gate in `ci.yml`. D-numbers are `design.md`'s decisions. `arc-reference/README.md` holds Arc's behavior and measurements. `quality.yml` runs on the branch before merging (`gh workflow run quality.yml --ref `), since the change alters menus and views the runtime suite drives. + +Suggested order: +1. Group 1. +2. Then groups 2 and 3 in parallel, with group 3 working against `FakeHost` while the engine builds. +3. Then groups 4 to 6. + +## 1. Contract and fakes + +- [ ] 1.1 Add to `ClairBrowser` in `native/ClairHost.h`, documented as the header documents the rest: + - `-requestPreviewOfTab:size:completion:` (D4); + - `-showTab:`, which shows a tab of any of the window's Spaces, switching Space, and swapping windows for another profile's Space as `-[ClairHost showSpace:]` does. + + Verify that the header compiles in `ClairHostObjCxxTests.mm` in CI. +- [ ] 1.2 Update `FakeBrowser` and `FakeHost`: + - previews per tab (set by tests, nil by default); + - `showTab` across Spaces, which posts `shownSpaceDidChange` before `activeTabDidChange`. + + Verify with new cases in `FakeBrowserTests` in CI. + +## 2. Engine + +- [ ] 2.1 Delete Chromium's Tab menu in `clair_window_hooks.mm`'s main-menu setup (D5), before any window becomes main. Verify in the engine build (2.5) that Clair starts with no Tab menu, and that switching windows and profiles doesn't crash: `AppController`'s `TabMenuBridge` and `onVerticalTabStripModeChanged` get nil. +- [ ] 2.2 Remove the engine's handling of Tab-menu-only commands (D5a): + - in `ExecuteTabCommand`: `IDC_CYCLE_TO_NEXT_TAB`, `IDC_CYCLE_TO_PREV_TAB`, `IDC_WINDOW_CLOSE_TABS_TO_RIGHT` and `IDC_WINDOW_CLOSE_OTHER_TABS`; + - in `ClairPeeks::ExecuteCommand`: `IDC_DUPLICATE_TAB` and `IDC_MOVE_TAB_TO_NEW_WINDOW`; + - the same four commands in the native window's modal-dialog validation list; + - `IDC_TAB_SEARCH`, `IDC_WINDOW_GROUP_TAB`, `IDC_GROUP_TARGET_TAB` and `IDC_NEW_SPLIT_TAB` from `ClairIsRemovedCommand`. + + Before each, grep the Chromium tree (`/Volumes/My Shared Files/clair/build/src`) for other senders of the command, and keep any case that has one, noting why in D5a. Verify that the engine compiles (2.5), and that Opt+Cmd+Down and Up, Cmd+1…9 and Close Tabs Below still work in the runtime suite (5.2). +- [ ] 2.3 Add `ClairTabPreview` (`engine/overlay/chrome/browser/clair/window/`), as D4 describes: + - on each active-tab change, `CopyPage` copies the outgoing row's page (each pane of a split), scales it to 2× the card width and cuts it to 3:2 from the top; + - the copy is kept as `WebContents` user data and replaced on each hide; + - `-requestPreviewOfTab:size:completion:` returns it, or copies the shown tab live, or nil. + + Verify in the hand check (6.1) that a background tab's card shows its page as left, and the shown tab's card its live page. +- [ ] 2.4 Implement `-showTab:` in `clair_browser_bridge.mm`: + - a tab of the shown Space activates as `-activateTab:` does, taking it from another window; + - a tab of another Space of the same profile shows that Space with the tab active; + - a tab of another profile's Space goes through the profile swap of `ShowSpace`, and the incoming window activates the tab. + + Verify with the runtime test of 5.3. +- [ ] 2.5 Push the branch and build the engine (`gh workflow run engine.yml -f ref=`). Verify that `chromium-engine-` is published. + +## 3. ClairUI + +- [ ] 3.1 Add `RecentTabs` (D1): the front-on-show rule, splits and Peeks as their row, the still's placeholder left out, pruning on tab and pin changes, and no cap, so open tabs never fall off the list. The incoming window takes the list on a profile swap. Verify with unit tests in CI for each scenario of `tab-switcher` "Recent tabs". +- [ ] 3.2 Add `SwitcherState` (D2, D3): open forward or back, step and wrap, commit, cancel, no-op with fewer than two entries, at most five cards, and the 100 ms delay before the panel shows (at once on a second Tab, never on a commit before it). Verify with unit tests in CI, with an injected clock, for the scenarios of "Opening the switcher", "Moving the selection", "Choosing a tab", "Cancelling the switcher" and "A quick Ctrl+Tab shows no panel". +- [ ] 3.3 Add `TabSwitcher`: + - the local key and mouse monitors of D2, acting only in a normal browser window with no dialog or sheet; + - commit through `showTab`; + - cancel on resign-key and when the shown tab closes. + + Verify with unit tests in CI that feed it synthetic `NSEvent`s: Ctrl+Tab is swallowed, other keys pass while it's closed, releasing Ctrl commits, and a click on a card (with Ctrl held) commits that card. +- [ ] 3.4 Add the switcher panel (D3): the child `NSPanel`, the cards with previews (a split's composed in pane order), favicons and titles or custom names, the accent highlight, centring kept on screen, no animation, and the identifiers of D7. Verify with a unit test of the layout maths (panel size for one to five cards, the clamp to the screen's visible frame) in CI, and by the hand check (6.1). +- [ ] 3.5 Add `TabsMenu` (D5), before the Window menu: Pin Tab, the new Pin to Favorites, New Folder…, Next and Previous Tab through `commandDispatch:`, Split with Tab › (moved from `SplitMenu`), Move to Space ›, and Clear Unpinned Tabs, with the enabled rules of `tabs-menu`. Verify with unit tests in CI for the items, their order, titles, shortcuts and enabled states, including incognito and a favorite. +- [ ] 3.6 Remove ClairUI's customizations of Chromium's Tab menu (D5a): + - `PinsMenu` keeps only View › Collapse Pinned Tabs, without `tabMenuTag` or the hiding of Chromium's pin items; + - `MainMenuCommand.backToPinnedURL` and `.closeKeepingPin` go; + - `SplitMenu` keeps only its View items; + - `SplitTests` and `FoldersTests` drop their fake Tab menus. + + Verify with `grep -rn "tabMenuTag\|35013\|35051" native/` finding nothing, and the unit tests passing in CI. +- [ ] 3.7 Rebuild `PinsLogic`'s menus as groups (D6): the Today, pinned and favorite menus, Close Tab on an open pinned tab (as Close and Keep Pinned), and the split chip's Separate Tabs in Split with Tab's place. Add Back to Pinned URL to Edit Pinned Page ›. Verify with unit tests in CI for each menu scenario in the `sidebar`, `pinned-tabs`, `favorites` and `split-view` deltas, including incognito and one Space. +- [ ] 3.8 Rename the sidebar Clear button's tooltip to "Clear unpinned tabs" (`PinsViews`). Verify with `grep -rn '"[^"]*Today[^"]*"' native/ClairUI` finding no user-facing string. + +## 4. Probe tooling + +- [ ] 4.1 Add `tests/probe/tools/keys.swift` (D8): steps `ctrldown`, `ctrlup`, `shiftdown`, `shiftup`, `tab`, `esc`, `sleep:` and `shot::`. Build it in `tools/build.sh`, and document it in the README beside `drag` and `mouse`. Verify by running `build/probe/bin/keys ctrldown tab sleep:0.5 shot:… ctrlup` against Arc and seeing the switcher in the shot. + +## 5. Runtime suite + +- [ ] 5.1 Move the runtime suite to the Tabs menu: `PinsTests.tabMenu` reads "Tabs", Clear Today becomes Clear Unpinned Tabs, and Back to Pinned URL is tested through the row's icon and Edit Pinned Page ›. `FoldersTests` and `SplitViewTests` follow. Add a check that the menu bar has no "Tab" menu. Verify by the suite passing in `quality.yml` on the branch. +- [ ] 5.2 Add `TabSwitcherTests`, using `perform(withKeyModifiers: .control)` to hold Ctrl: + - a quick Ctrl+Tab returns to the previous tab, and `clair.tabSwitcher` never appears; + - while held, `clair.tabSwitcher` shows the recent tabs' cards, the second selected; + - Esc keeps the tab; + - clicking a card with Ctrl held shows that tab; + - Opt+Cmd+Down still steps through the rows. + + Verify by the suite passing in `quality.yml`. +- [ ] 5.3 Add a cross-Space case: a tab shown in another Space comes back with Ctrl+Tab, and the window switches Space. Verify by the suite passing in `quality.yml`. +- [ ] 5.4 Add context menu checks: a Today tab's menu items and dividers in order, and a pinned tab's Close Tab keeping its row. Verify by the suite passing in `quality.yml`. + +## 6. Hand check, docs and release notes + +- [ ] 6.1 Hand check with `tests/probe/launch-clair.sh` and the `keys` tool, against `arc-reference/`, with the same tabs: + - the panel's size and position; + - card and highlight sizes; + - previews of background and shown tabs, and of a split; + - stepping, wrapping and Esc; + - a quick tap: no panel in a 60 fps recording; + - no animation in a 60 fps recording. + + Record the numbers in `arc-reference/README.md` under "Clair", and fix any size or spacing more than 2 pt off Arc's. Check the panel's position against D3's rule (centred on the window, kept on screen), not Arc's absolute position. +- [ ] 6.2 Update the docs: + - `docs/native-window.md`'s "Rows and commands" (Ctrl+Tab leaves the row commands; the switcher and its previews get a short section); + - `docs/building.md`'s "Updating the engine" gains a note to grep Chromium for new `IDC_TAB_MENU` users (design "Risks"). + + Verify by reading both pages. +- [ ] 6.3 Add a Changie fragment (`changie new`) for the switcher, the Tabs menu and the tab menus. Verify that `.changes/unreleased/` holds it. +- [ ] 6.4 Run CI and `quality.yml` on the last push together, with every note in that push. Verify that both pass. + +## Workflow follow-up + +- After the implementation PR merges, one docs-only PR ticks the tasks the last checks verified, syncs the delta specs and archives the change. +- Delete the temporary probe screenshots in the scratchpad and `build/probe/` once the change is archived. `arc-reference/screenshots/` stays with the change.