From f3df650c393a6bd6f1400aea9bf4399993e7609e Mon Sep 17 00:00:00 2001 From: aamott <54421854+aamott@users.noreply.github.com> Date: Sat, 17 Oct 2026 11:04:02 -0600 Subject: [PATCH 1/9] Make the tab close button a visible square hover chip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The close affordance was a bare glyph with uneven padding — hard to hit and invisible as a target. It now matches the title bar's other square chips: fixed 1.6rem rounded square, accent fill on hover, sitting a step from the tab's right edge. --- apps/desktop/src/shell/TitleBar.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/shell/TitleBar.tsx b/apps/desktop/src/shell/TitleBar.tsx index f5c690d3..12f6743f 100644 --- a/apps/desktop/src/shell/TitleBar.tsx +++ b/apps/desktop/src/shell/TitleBar.tsx @@ -1,5 +1,5 @@ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"; -import { ArrowLeft, ArrowRight, MoreHorizontal, Pin, Plus } from "lucide-react"; +import { ArrowLeft, ArrowRight, MoreHorizontal, Pin, Plus, X } from "lucide-react"; import { cn } from "../lib/utils"; import { tabAccessibleName, type DesktopTab } from "../tabs/tabModel"; import { useRightPanelContributions, type RightPanelContribution } from "../panels/panelRegistryModel"; @@ -330,13 +330,17 @@ export function TitleBar({ {tab.title} {tab.isDirty && } + {/* Square hover chip, matching the back/forward/menu buttons: + the fill makes the hitbox visible and the fixed size keeps + the target easy to hit. Sits a step from the tab's right + edge rather than inside the title's padding. */} ); From 52244ecf835d58694849a287eb2638de9d712152 Mon Sep 17 00:00:00 2001 From: aamott <54421854+aamott@users.noreply.github.com> Date: Sat, 17 Oct 2026 11:15:20 -0600 Subject: [PATCH 2/9] Add pointer-driven tab reordering Preview tab displacement and scroll at strip edges without changing navigation history. Expose palette commands for keyboard reordering and preserve click behavior below the drag threshold. --- .../src/commands/commandRegistry.test.ts | 15 ++ apps/desktop/src/commands/commandRegistry.ts | 14 ++ apps/desktop/src/shell/DesktopShell.tsx | 1 + apps/desktop/src/shell/TitleBar.test.tsx | 1 + apps/desktop/src/shell/TitleBar.tsx | 21 ++- apps/desktop/src/shell/useShellCommands.ts | 14 +- .../src/shell/useTabStripDrag.test.tsx | 153 +++++++++++++++++ apps/desktop/src/shell/useTabStripDrag.ts | 154 ++++++++++++++++++ apps/desktop/src/tabs/tabModel.ts | 3 + apps/desktop/src/tabs/tabReorder.test.ts | 33 ++++ apps/desktop/src/tabs/tabReorder.ts | 19 +++ .../WorkspaceExplorer.create.test.tsx | 2 + 12 files changed, 426 insertions(+), 4 deletions(-) create mode 100644 apps/desktop/src/shell/useTabStripDrag.test.tsx create mode 100644 apps/desktop/src/shell/useTabStripDrag.ts create mode 100644 apps/desktop/src/tabs/tabReorder.test.ts create mode 100644 apps/desktop/src/tabs/tabReorder.ts diff --git a/apps/desktop/src/commands/commandRegistry.test.ts b/apps/desktop/src/commands/commandRegistry.test.ts index 61a4285f..1f31f60d 100644 --- a/apps/desktop/src/commands/commandRegistry.test.ts +++ b/apps/desktop/src/commands/commandRegistry.test.ts @@ -16,6 +16,8 @@ const commandContext: DesktopCommandContext = { toggleAssistant: () => undefined, toggleBottomPanel: () => undefined, toggleLivePreview: () => undefined, + moveTabLeft: () => undefined, + moveTabRight: () => undefined, revealPanel: () => undefined, revealLeftPanel: () => undefined, openSettings: () => undefined, @@ -25,10 +27,23 @@ const commandContext: DesktopCommandContext = { }; describe("desktop command registry", () => { + it("runs tab movement through the shell and closes the palette", () => { + const moveTabLeft = vi.fn(); + const moveTabRight = vi.fn(); + const closePalette = vi.fn(); + const context = { ...commandContext, moveTabLeft, moveTabRight, closePalette }; + const registry = createDesktopCommandRegistry(); + registry.get("move-tab-left")?.handler(context); + registry.get("move-tab-right")?.handler(context); + expect(moveTabLeft).toHaveBeenCalledOnce(); + expect(moveTabRight).toHaveBeenCalledOnce(); + expect(closePalette).toHaveBeenCalledTimes(2); + }); it("provides the shell commands needed by the command palette", () => { const registry = createDesktopCommandRegistry(); expect(registry.entries().map((command) => command.id)).toEqual([ + "move-tab-left", "move-tab-right", "new-note", "search", "go-back", "go-forward", "toggle-live-preview", "toggle-theme", "toggle-explorer", "toggle-outline", "toggle-assistant", "toggle-bottom-panel", diff --git a/apps/desktop/src/commands/commandRegistry.ts b/apps/desktop/src/commands/commandRegistry.ts index 2949cc3d..8f5101a4 100644 --- a/apps/desktop/src/commands/commandRegistry.ts +++ b/apps/desktop/src/commands/commandRegistry.ts @@ -32,6 +32,8 @@ export interface DesktopCommandContext { readonly toggleAssistant: () => void; readonly toggleBottomPanel: () => void; readonly toggleLivePreview: () => void; + readonly moveTabLeft: () => void; + readonly moveTabRight: () => void; /** Reveals a panel by its fully-qualified id, opening its side popout — either dock. */ readonly revealPanel: (panelId: string) => void; /** Reveals a left-side panel by id; admits registered extension panels too. */ @@ -96,6 +98,18 @@ const withClosePalette = (action: NoArgContextAction) => (context: DesktopComman /** First-party command ownership and availability are explicit and testable. */ export const builtInDesktopCommands: readonly DesktopCommand[] = [ + available({ + id: "move-tab-left", + title: "Move tab left", + keywords: ["reorder"], + handler: withClosePalette("moveTabLeft") + }), + available({ + id: "move-tab-right", + title: "Move tab right", + keywords: ["reorder"], + handler: withClosePalette("moveTabRight") + }), available({ id: "new-note", title: "New note", diff --git a/apps/desktop/src/shell/DesktopShell.tsx b/apps/desktop/src/shell/DesktopShell.tsx index fea40099..71daa692 100644 --- a/apps/desktop/src/shell/DesktopShell.tsx +++ b/apps/desktop/src/shell/DesktopShell.tsx @@ -165,6 +165,7 @@ export function DesktopShell({ shell }: { readonly shell: ShellState }) { onSelectTab={(tabId) => dispatchTabs({ type: "activate", tabId })} onRequestCloseTab={(tabId) => dispatchTabs({ type: "requestClose", tabId })} onKeepTab={(tabId) => dispatchTabs({ type: "keep", tabId })} + onReorderTab={(tabId, toIndex) => dispatchTabs({ type: "reorder", tabId, toIndex })} onNewTab={() => shell.openNewTab()} onToggleRightPanel={shell.toggleRightPanel} onOpenCommandPalette={shell.openPalette} diff --git a/apps/desktop/src/shell/TitleBar.test.tsx b/apps/desktop/src/shell/TitleBar.test.tsx index bf004cdd..0b08fbed 100644 --- a/apps/desktop/src/shell/TitleBar.test.tsx +++ b/apps/desktop/src/shell/TitleBar.test.tsx @@ -47,6 +47,7 @@ const render = async (props: { onSelectTab={() => undefined} onRequestCloseTab={() => undefined} onKeepTab={props.onKeepTab ?? (() => undefined)} + onReorderTab={() => undefined} onNewTab={props.onNewTab ?? (() => undefined)} onToggleRightPanel={props.onToggleRightPanel ?? (() => undefined)} onOpenCommandPalette={() => undefined} diff --git a/apps/desktop/src/shell/TitleBar.tsx b/apps/desktop/src/shell/TitleBar.tsx index 12f6743f..9f40c10c 100644 --- a/apps/desktop/src/shell/TitleBar.tsx +++ b/apps/desktop/src/shell/TitleBar.tsx @@ -16,6 +16,7 @@ import { serializePinnedActionItems } from "./actionItemsModel"; import { WorkspaceSwitchingSelector } from "../workspace/WorkspaceSwitching"; +import { useTabStripDrag } from "./useTabStripDrag"; /** * Back/Forward chrome: the ⌘ command-palette button's sizing, with hover @@ -61,6 +62,7 @@ type TitleBarProps = { readonly onRequestCloseTab: (tabId: string) => void; /** Called when the user double-clicks a tab, keeping a preview open. */ readonly onKeepTab: (tabId: string) => void; + readonly onReorderTab: (tabId: string, toIndex: number) => void; /** Called when the user clicks the strip's "+" affordance. */ readonly onNewTab: () => void; /** Called when the user toggles a right-dock panel button. */ @@ -107,6 +109,7 @@ export function TitleBar({ onSelectTab, onRequestCloseTab, onKeepTab, + onReorderTab, onNewTab, onToggleRightPanel, onOpenCommandPalette, @@ -175,6 +178,7 @@ export function TitleBar({ // non-passive native listener so preventDefault works (React's onWheel is // passive at the root and would warn / no-op on preventDefault). const tabStripRef = useRef(null); + const tabDrag = useTabStripDrag(tabStripRef, tabs, onReorderTab); useEffect(() => { const el = tabStripRef.current; if (!el) return; @@ -293,8 +297,17 @@ export function TitleBar({ className="tn-scrollbar-none flex items-end gap-0.5 h-full min-w-0 overflow-x-auto" aria-label="Open tabs" onScroll={measureScrollEdges} + onClickCapture={(event) => { + if (event.detail > 0 && tabDrag.suppressClick()) { + event.preventDefault(); + event.stopPropagation(); + } + }} + onDoubleClickCapture={(event) => { + if (tabDrag.suppressClick()) event.stopPropagation(); + }} > - {tabs.map((tab) => { + {tabs.map((tab, index) => { const isActive = tab.id === activeTabId; // Restore previews of one file share a title; the accessible name // and tooltip carry the version's date so they stay distinct. @@ -303,19 +316,23 @@ export function TitleBar({
{ if (el) tabElementsRef.current.set(tab.id, el); else tabElementsRef.current.delete(tab.id); }} className={cn( "flex items-center bg-tab-inactive text-tab-inactive-foreground border-t-2 border-t-transparent rounded-t-small flex-[0_0_clamp(7.5rem,15vw,12.5rem)] max-[760px]:flex-basis-[7.25rem] text-xs h-[calc(100%-3px)] min-w-0 hover:bg-secondary", - isActive && "bg-tab-active border-t-primary text-tab-active-foreground" + isActive && "bg-tab-active border-t-primary text-tab-active-foreground", + tabDrag.draggedTabId === tab.id && "relative z-10 opacity-90 shadow-md ring-1 ring-border" )} >
- {/* Always visible, unlike the hover-reveal create icons: ordering - is a standing preference, not an occasional action. */} + {/* Ordering is a standing preference, not an occasional action. */} Date: Sat, 17 Oct 2026 11:38:06 -0600 Subject: [PATCH 7/9] Add right-click context menu to editor tabs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Right-clicking a tab opens a pointer-placed menu (shared Menu surface) with Close routed through the existing dirty-guard flow, plus Close others / Close tabs to the right implemented as a closeMultiple reducer action in a sibling module since tabModel.ts is at the file-size cap. Copy path works for file-backed tabs; Reveal in explorer and Pin tab are rendered disabled as not implemented — neither capability exists yet. Multi-close items stub themselves likewise when a dirty tab sits in the target set, since no multi-tab confirmation flow exists. --- apps/desktop/src/shell/DesktopShell.tsx | 2 + apps/desktop/src/shell/TabContextMenu.tsx | 96 ++++++++++++ apps/desktop/src/shell/TitleBar.test.tsx | 152 ++++++++++++++++++- apps/desktop/src/shell/TitleBar.tsx | 28 ++++ apps/desktop/src/shell/useLocationHistory.ts | 2 + apps/desktop/src/tabs/tabClose.test.ts | 95 ++++++++++++ apps/desktop/src/tabs/tabClose.ts | 42 +++++ apps/desktop/src/tabs/tabModel.ts | 9 +- 8 files changed, 420 insertions(+), 6 deletions(-) create mode 100644 apps/desktop/src/shell/TabContextMenu.tsx create mode 100644 apps/desktop/src/tabs/tabClose.test.ts create mode 100644 apps/desktop/src/tabs/tabClose.ts diff --git a/apps/desktop/src/shell/DesktopShell.tsx b/apps/desktop/src/shell/DesktopShell.tsx index 71daa692..fdc7ccc6 100644 --- a/apps/desktop/src/shell/DesktopShell.tsx +++ b/apps/desktop/src/shell/DesktopShell.tsx @@ -164,6 +164,8 @@ export function DesktopShell({ shell }: { readonly shell: ShellState }) { onForward={() => dispatchTabs({ type: "goForward" })} onSelectTab={(tabId) => dispatchTabs({ type: "activate", tabId })} onRequestCloseTab={(tabId) => dispatchTabs({ type: "requestClose", tabId })} + onCloseOtherTabs={(tabId) => dispatchTabs({ type: "closeMultiple", tabId, scope: "others" })} + onCloseTabsToRight={(tabId) => dispatchTabs({ type: "closeMultiple", tabId, scope: "right" })} onKeepTab={(tabId) => dispatchTabs({ type: "keep", tabId })} onReorderTab={(tabId, toIndex) => dispatchTabs({ type: "reorder", tabId, toIndex })} onNewTab={() => shell.openNewTab()} diff --git a/apps/desktop/src/shell/TabContextMenu.tsx b/apps/desktop/src/shell/TabContextMenu.tsx new file mode 100644 index 00000000..6a4700bd --- /dev/null +++ b/apps/desktop/src/shell/TabContextMenu.tsx @@ -0,0 +1,96 @@ +import { isFileResourceTab, tabAccessibleName, type DesktopTab } from "../tabs/tabModel"; +import { Menu, MenuButton, MenuSeparator, type MenuPosition } from "./Menu"; + +/** Where a tab's right-click menu was asked for, plus the tab it is about. */ +export type TabMenuState = MenuPosition & { readonly tabId: string }; + +const NOT_IMPLEMENTED = "Not implemented yet"; + +/** + * Right-click menu for an open tab. + * + * Only placement is this component's — every behaviour (focus, arrow keys, + * Escape, closing on an outside pointer) is the shared {@link Menu}'s. + * "Close" routes through the same request-close path the close chip uses, so + * a dirty tab still earns its save/discard/cancel dialog. + */ +export function TabContextMenu({ + menu, + tabs, + onClose, + onRequestCloseTab, + onCloseOtherTabs, + onCloseTabsToRight, +}: { + readonly menu: TabMenuState; + readonly tabs: readonly DesktopTab[]; + readonly onClose: () => void; + readonly onRequestCloseTab: (tabId: string) => void; + readonly onCloseOtherTabs: (tabId: string) => void; + readonly onCloseTabsToRight: (tabId: string) => void; +}) { + const index = tabs.findIndex((tab) => tab.id === menu.tabId); + const tab = index < 0 ? null : tabs[index]!; + if (tab === null) return null; + + const others = tabs.filter((candidate) => candidate.id !== tab.id); + const toRight = tabs.slice(index + 1); + // A multi-close has no dirty guard to offer — when a dirty tab sits in the + // target set the item is stubbed rather than silently skipping real work. + const othersDirty = others.some((candidate) => candidate.isDirty); + const rightDirty = toRight.some((candidate) => candidate.isDirty); + + const resource = tab.resource; + const filePath = + isFileResourceTab(tab) && resource?.rootPath !== undefined && resource.relativePath !== undefined + ? `${resource.rootPath}/${resource.relativePath}` + : null; + + const copyPath = () => { + if (filePath === null) return; + void navigator.clipboard?.writeText(filePath)?.catch((error: unknown) => { + console.error("[titlebar] Could not copy the tab path to the clipboard.", error); + }); + onClose(); + }; + + return ( + + { + onClose(); + onRequestCloseTab(tab.id); + }} + /> + { + onClose(); + onCloseOtherTabs(tab.id); + }} + /> + { + onClose(); + onCloseTabsToRight(tab.id); + }} + /> + + {filePath !== null && ( + <> + + {/* No explorer reveal/select entry exists yet — stub until one does. */} + undefined} /> + + )} + {/* Pinning is not part of the tab model — stub until it exists. */} + undefined} /> + + ); +} diff --git a/apps/desktop/src/shell/TitleBar.test.tsx b/apps/desktop/src/shell/TitleBar.test.tsx index 0b08fbed..96d66fbb 100644 --- a/apps/desktop/src/shell/TitleBar.test.tsx +++ b/apps/desktop/src/shell/TitleBar.test.tsx @@ -25,6 +25,9 @@ const render = async (props: { readonly onForward?: () => void; readonly onToggleRightPanel?: (panel: RightPanel) => void; readonly onKeepTab?: (tabId: string) => void; + readonly onRequestCloseTab?: (tabId: string) => void; + readonly onCloseOtherTabs?: (tabId: string) => void; + readonly onCloseTabsToRight?: (tabId: string) => void; readonly onNewTab?: () => void; readonly isPanelAvailable?: (panelId: string) => boolean; } = {}): Promise => { @@ -45,7 +48,9 @@ const render = async (props: { onBack={props.onBack ?? (() => undefined)} onForward={props.onForward ?? (() => undefined)} onSelectTab={() => undefined} - onRequestCloseTab={() => undefined} + onRequestCloseTab={props.onRequestCloseTab ?? (() => undefined)} + onCloseOtherTabs={props.onCloseOtherTabs ?? (() => undefined)} + onCloseTabsToRight={props.onCloseTabsToRight ?? (() => undefined)} onKeepTab={props.onKeepTab ?? (() => undefined)} onReorderTab={() => undefined} onNewTab={props.onNewTab ?? (() => undefined)} @@ -490,4 +495,149 @@ describe("TitleBar", () => { }); expect(onKeepTab).toHaveBeenCalledWith("t1"); }); + + describe("tab context menu", () => { + // Pointer-placed menus portal to document.body; find this tab's there. + const tabMenuFor = (name: string): HTMLElement | null => + [...document.querySelectorAll('[role="menu"]')] + .find((el) => el.getAttribute("aria-label") === `${name} options`) ?? null; + + const rightClickTab = async (host: HTMLElement, tabId: string): Promise => { + const chip = host.querySelector(`[data-tab-id="${tabId}"]`); + if (!chip) throw new Error(`Tab ${tabId} missing`); + await act(async () => { + chip.dispatchEvent( + new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: 15, clientY: 9 }) + ); + }); + }; + + const menuItem = (menu: HTMLElement, label: string): HTMLButtonElement | undefined => + [...menu.querySelectorAll('[role="menuitem"]')] + .find((item) => item.textContent === label); + + const editorTab = (name: string) => + createEditorTab({ rootPath: "/notes", relativePath: `dir/${name}.md` }); + + it("opens on right-click with the tab's actions in order", async () => { + const host = await render({ tabs: [editorTab("a")] }); + + await rightClickTab(host, editorTab("a").id); + + const menu = tabMenuFor("a.md"); + expect(menu).not.toBeNull(); + expect([...menu!.querySelectorAll('[role="menuitem"]')].map((item) => item.textContent)) + .toEqual([ + "Close", + "Close other tabs", + "Close tabs to the right", + "Copy path", + "Reveal in explorer", + "Pin tab" + ]); + }); + + it("routes Close through the same request-close path as the close chip", async () => { + const onRequestCloseTab = vi.fn(); + const tab = editorTab("a"); + const host = await render({ tabs: [tab], onRequestCloseTab }); + + await rightClickTab(host, tab.id); + await act(async () => menuItem(tabMenuFor("a.md")!, "Close")!.click()); + + expect(onRequestCloseTab).toHaveBeenCalledWith(tab.id); + expect(tabMenuFor("a.md")).toBeNull(); + }); + + it("closes every clean tab except the clicked one via the shell callback", async () => { + const onCloseOtherTabs = vi.fn(); + const tabs = [editorTab("a"), editorTab("b"), editorTab("c")]; + const host = await render({ tabs, onCloseOtherTabs }); + + await rightClickTab(host, tabs[0]!.id); + await act(async () => menuItem(tabMenuFor("a.md")!, "Close other tabs")!.click()); + + expect(onCloseOtherTabs).toHaveBeenCalledWith(tabs[0]!.id); + expect(tabMenuFor("a.md")).toBeNull(); + }); + + it("closes clean tabs to the right via the shell callback", async () => { + const onCloseTabsToRight = vi.fn(); + const tabs = [editorTab("a"), editorTab("b"), editorTab("c")]; + const host = await render({ tabs, onCloseTabsToRight }); + + await rightClickTab(host, tabs[0]!.id); + await act(async () => menuItem(tabMenuFor("a.md")!, "Close tabs to the right")!.click()); + + expect(onCloseTabsToRight).toHaveBeenCalledWith(tabs[0]!.id); + expect(tabMenuFor("a.md")).toBeNull(); + }); + + it("stubs the multi-close items when a dirty tab sits in their target set", async () => { + const dirty = { id: "settings", title: "Settings", kind: "settings", isDirty: true } as const; + const tabs = [editorTab("a"), dirty, editorTab("c")]; + const host = await render({ tabs }); + + await rightClickTab(host, tabs[0]!.id); + const menu = tabMenuFor("a.md")!; + + for (const label of ["Close other tabs", "Close tabs to the right"]) { + const item = menuItem(menu, label)!; + expect(item.disabled).toBe(true); + expect(item.getAttribute("title")).toBe("Not implemented yet"); + } + }); + + it("copies the file's absolute path for an editor tab", async () => { + const writeText = vi.fn<(text: string) => Promise>().mockResolvedValue(undefined); + vi.stubGlobal("navigator", { clipboard: { writeText } }); + const tab = editorTab("a"); + const host = await render({ tabs: [tab] }); + + await rightClickTab(host, tab.id); + await act(async () => menuItem(tabMenuFor("a.md")!, "Copy path")!.click()); + + expect(writeText).toHaveBeenCalledWith("/notes/dir/a.md"); + expect(tabMenuFor("a.md")).toBeNull(); + }); + + it("hides the file actions on a tab with no file behind it", async () => { + const host = await render({ + tabs: [{ id: "settings", title: "Settings", kind: "settings" }] + }); + + await rightClickTab(host, "settings"); + const menu = tabMenuFor("Settings")!; + + expect(menuItem(menu, "Copy path")).toBeUndefined(); + expect(menuItem(menu, "Reveal in explorer")).toBeUndefined(); + expect(menuItem(menu, "Pin tab")).not.toBeUndefined(); + }); + + it("renders Pin tab and Reveal in explorer disabled as not implemented", async () => { + const host = await render({ tabs: [editorTab("a")] }); + + await rightClickTab(host, editorTab("a").id); + const menu = tabMenuFor("a.md")!; + + for (const label of ["Reveal in explorer", "Pin tab"]) { + const item = menuItem(menu, label)!; + expect(item.disabled).toBe(true); + expect(item.getAttribute("title")).toBe("Not implemented yet"); + } + }); + + it("closes on Escape", async () => { + const host = await render({ tabs: [editorTab("a")] }); + + await rightClickTab(host, editorTab("a").id); + expect(tabMenuFor("a.md")).not.toBeNull(); + + await act(async () => { + tabMenuFor("a.md")!.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true })); + }); + + expect(tabMenuFor("a.md")).toBeNull(); + }); + }); }); diff --git a/apps/desktop/src/shell/TitleBar.tsx b/apps/desktop/src/shell/TitleBar.tsx index 9f40c10c..23b8165b 100644 --- a/apps/desktop/src/shell/TitleBar.tsx +++ b/apps/desktop/src/shell/TitleBar.tsx @@ -8,6 +8,7 @@ import { useSettingsStore } from "../settings/settingsStore"; import { mediaQueryList, useMediaQuery } from "../lib/useMediaQuery"; import { IconButton } from "./IconButton"; import { Menu, MenuButton, MenuSeparator, MENU_ITEM, type MenuCloseReason, type MenuPosition } from "./Menu"; +import { TabContextMenu, type TabMenuState } from "./TabContextMenu"; import { PanelIcon } from "./panelIcons"; import { type RightPanel } from "./shellTypes"; import { @@ -60,6 +61,10 @@ type TitleBarProps = { readonly onSelectTab: (tabId: string) => void; /** Called when the user clicks a tab's close affordance. */ readonly onRequestCloseTab: (tabId: string) => void; + /** Called for "Close other tabs": every clean tab except `tabId` goes. */ + readonly onCloseOtherTabs: (tabId: string) => void; + /** Called for "Close tabs to the right": clean tabs after `tabId` go. */ + readonly onCloseTabsToRight: (tabId: string) => void; /** Called when the user double-clicks a tab, keeping a preview open. */ readonly onKeepTab: (tabId: string) => void; readonly onReorderTab: (tabId: string, toIndex: number) => void; @@ -108,6 +113,8 @@ export function TitleBar({ onForward, onSelectTab, onRequestCloseTab, + onCloseOtherTabs, + onCloseTabsToRight, onKeepTab, onReorderTab, onNewTab, @@ -120,6 +127,8 @@ export function TitleBar({ const actionsTriggerRef = useRef(null); // Right-click on a bar icon raises this pointer-placed menu for pin control. const [pinMenu, setPinMenu] = useState<(MenuPosition & { panel: RightPanelContribution }) | null>(null); + // Right-click on a tab raises its context menu the same way. + const [tabMenu, setTabMenu] = useState(null); // The ⋯ menu shows every panel below 900px (the icon row is hidden there) // and only the unpinned remainder above it — the pinned icons are already @@ -316,6 +325,12 @@ export function TitleBar({
{ + event.preventDefault(); + // One pointer-placed menu at a time. + setPinMenu(null); + setTabMenu({ x: event.clientX, y: event.clientY, tabId: tab.id }); + }} style={tabDrag.tabStyle(index)} ref={(el) => { if (el) tabElementsRef.current.set(tab.id, el); @@ -415,6 +430,7 @@ export function TitleBar({ onClick={() => onToggleRightPanel(action.id)} onContextMenu={(event) => { event.preventDefault(); + setTabMenu(null); setPinMenu({ x: event.clientX, y: event.clientY, panel: action }); }} /> @@ -428,6 +444,7 @@ export function TitleBar({ className="inline-flex w-[1.6rem] h-[1.6rem] items-center justify-center rounded-small text-titlebar-foreground opacity-40" onContextMenu={(event) => { event.preventDefault(); + setTabMenu(null); setPinMenu({ x: event.clientX, y: event.clientY, panel: action }); }} > @@ -538,6 +555,17 @@ export function TitleBar({ )}
+ + {tabMenu && ( + setTabMenu(null)} + onRequestCloseTab={onRequestCloseTab} + onCloseOtherTabs={onCloseOtherTabs} + onCloseTabsToRight={onCloseTabsToRight} + /> + )} ); } diff --git a/apps/desktop/src/shell/useLocationHistory.ts b/apps/desktop/src/shell/useLocationHistory.ts index c36e4585..e778b872 100644 --- a/apps/desktop/src/shell/useLocationHistory.ts +++ b/apps/desktop/src/shell/useLocationHistory.ts @@ -58,6 +58,8 @@ import type { DocumentViewState } from "./shellTypes"; const DEPARTURE_ACTIONS: ReadonlySet = new Set([ "open", "activate", + // A multi-close activates the right-clicked tab first — same departure. + "closeMultiple", "goBack", "goForward", "restoreVisit", diff --git a/apps/desktop/src/tabs/tabClose.test.ts b/apps/desktop/src/tabs/tabClose.test.ts new file mode 100644 index 00000000..a922677a --- /dev/null +++ b/apps/desktop/src/tabs/tabClose.test.ts @@ -0,0 +1,95 @@ +import { describe, expect, it } from "vitest"; +import { + createEditorTab, + desktopTabReducer, + initialDesktopTabState, + type DesktopTabState +} from "./tabModel"; + +const open = (state: DesktopTabState, name: string): DesktopTabState => + desktopTabReducer(state, { + type: "open", + tab: createEditorTab({ rootPath: "/notes", relativePath: `${name}.md` }) + }); + +const withTabs = (...names: readonly string[]): DesktopTabState => + names.reduce(open, initialDesktopTabState); + +const ids = (state: DesktopTabState): readonly string[] => state.tabs.map((tab) => tab.id); + +describe("closeMultiple", () => { + it("closes every clean tab except the clicked one and activates it", () => { + const state = withTabs("a", "b", "c"); + const target = state.tabs[0]!; + + const next = desktopTabReducer(state, { type: "closeMultiple", tabId: target.id, scope: "others" }); + + expect(ids(next)).toEqual([target.id]); + // The right-clicked tab is the survivor on screen, even though it was + // not the active one when the action landed. + expect(next.activeTabId).toBe(target.id); + }); + + it("closes only the clean tabs to the right of the clicked tab", () => { + const state = withTabs("a", "b", "c", "d"); + const target = state.tabs[1]!; + + const next = desktopTabReducer(state, { type: "closeMultiple", tabId: target.id, scope: "right" }); + + expect(ids(next)).toEqual([state.tabs[0]!.id, target.id]); + expect(next.activeTabId).toBe(target.id); + }); + + it("skips dirty targets instead of confirming them", () => { + let state = withTabs("a", "b", "c"); + const dirty = state.tabs[2]!; + state = desktopTabReducer(state, { type: "setDirty", tabId: dirty.id, isDirty: true }); + const target = state.tabs[0]!; + + const next = desktopTabReducer(state, { type: "closeMultiple", tabId: target.id, scope: "others" }); + + // b is gone; the dirty tab stays — closing it needs the dialog the + // menu declines to bypass. + expect(ids(next)).toEqual([target.id, dirty.id]); + expect(next.tabs[1]!.isDirty).toBe(true); + expect(next.activeTabId).toBe(target.id); + }); + + it("scrubs closed trails from history without touching the survivors'", () => { + const state = withTabs("a", "b", "c"); + const target = state.tabs[0]!; + + const next = desktopTabReducer(state, { type: "closeMultiple", tabId: target.id, scope: "others" }); + + // Only the surviving trail keeps visits; the cursor sits on its entry. + expect(next.history.entries).toHaveLength(1); + expect(next.history.entries[0]!.tab.id).toBe(target.id); + expect(next.history.cursor).toBe(0); + }); + + it("keeps a parked close request whose dirty tab survived", () => { + let state = withTabs("a", "b", "c"); + const dirty = state.tabs[2]!; + state = desktopTabReducer(state, { type: "setDirty", tabId: dirty.id, isDirty: true }); + state = desktopTabReducer(state, { type: "requestClose", tabId: dirty.id }); + expect(state.closeRequest?.tabId).toBe(dirty.id); + const target = state.tabs[0]!; + + const next = desktopTabReducer(state, { type: "closeMultiple", tabId: target.id, scope: "others" }); + + expect(ids(next)).toEqual([target.id, dirty.id]); + // The unanswered dialog belongs to a tab that is still open — it must + // not be swallowed by the removals around it. + expect(next.closeRequest?.tabId).toBe(dirty.id); + }); + + it("is a no-op for an unknown tab", () => { + const state = withTabs("a", "b"); + expect( + desktopTabReducer(state, { type: "closeMultiple", tabId: "missing", scope: "others" }) + ).toBe(state); + expect( + desktopTabReducer(state, { type: "closeMultiple", tabId: "missing", scope: "right" }) + ).toBe(state); + }); +}); diff --git a/apps/desktop/src/tabs/tabClose.ts b/apps/desktop/src/tabs/tabClose.ts new file mode 100644 index 00000000..f2d2fb34 --- /dev/null +++ b/apps/desktop/src/tabs/tabClose.ts @@ -0,0 +1,42 @@ +import { activateExistingTab, removeTab } from "./tabHistory"; +import type { DesktopTabState } from "./tabModel"; + +/** Which neighbours of `tabId` a multi-close targets. */ +export type TabCloseScope = "others" | "right"; + +export interface TabCloseMultipleAction { + readonly type: "closeMultiple"; + readonly tabId: string; + readonly scope: TabCloseScope; +} + +/** + * "Close other tabs" / "Close tabs to the right" from a tab's context menu. + * + * The clicked tab becomes the survivor on screen first — VS Code semantics — + * so `activeTabId` stays valid no matter which neighbours go. Dirty targets + * are *skipped*, not confirmed: no multi-tab dirty guard exists, and the menu + * refuses the action when one sits in the target set. Each removal runs the + * ordinary single-close helper, so trail scrubbing and preview handling can + * never drift from the close chip's behaviour. + */ +export function closeMultipleTabs( + state: DesktopTabState, + { tabId, scope }: TabCloseMultipleAction +): DesktopTabState { + const index = state.tabs.findIndex((tab) => tab.id === tabId); + if (index < 0) return state; + let next = activateExistingTab(state, tabId); + const targets = next.tabs.filter((tab, i) => { + if (tab.id === tabId || tab.isDirty) return false; + return scope === "others" || i > index; + }); + for (const tab of targets) next = removeTab(next, tab.id); + // removeTab clears closeRequest unconditionally; a request parked on a + // surviving (dirty) tab must keep its dialog rather than be swallowed. + const request = next.closeRequest ?? state.closeRequest; + if (request && next.tabs.some((tab) => tab.id === request.tabId)) { + next = { ...next, closeRequest: request }; + } + return next; +} diff --git a/apps/desktop/src/tabs/tabModel.ts b/apps/desktop/src/tabs/tabModel.ts index cc83d8d0..69526680 100644 --- a/apps/desktop/src/tabs/tabModel.ts +++ b/apps/desktop/src/tabs/tabModel.ts @@ -2,6 +2,7 @@ import type { Tab, TabKind, TabResource } from "@thinkbrain/core"; import { inferTabKind } from "@thinkbrain/core"; import type { ChangeDesc } from "@codemirror/state"; import { reorderTab, type TabReorderAction } from "./tabReorder"; +import { closeMultipleTabs, type TabCloseMultipleAction } from "./tabClose"; import { activateExistingTab, @@ -85,15 +86,11 @@ export function isDocumentBackedKind(kind: string): boolean { return DOCUMENT_BACKED_KINDS.has(kind); } -interface CloseRequest { - readonly tabId: string; -} - export interface DesktopTabState { readonly tabs: readonly DesktopTab[]; readonly activeTabId: string | null; /** Present only when a dirty tab needs a save/discard/cancel decision. */ - readonly closeRequest: CloseRequest | null; + readonly closeRequest: { readonly tabId: string } | null; readonly history: DesktopTabHistory; } @@ -113,6 +110,7 @@ export type TabOpenPlacement = "new" | "preview" | "replace-active"; export type DesktopTabAction = | TabReorderAction + | TabCloseMultipleAction | { readonly type: "open"; readonly tab: DesktopTab; readonly placement?: TabOpenPlacement } | { readonly type: "keep"; readonly tabId: string } | { readonly type: "activate"; readonly tabId: string } @@ -361,6 +359,7 @@ export function desktopTabReducer( ): DesktopTabState { switch (action.type) { case "reorder": return reorderTab(state, action); + case "closeMultiple": return closeMultipleTabs(state, action); case "open": { const prepared = prepareTabOpen(state, action.tab, action.placement); if (prepared.kind === "noop") return state; From 43c310283f753d412154b5928c00f92df48e9b5b Mon Sep 17 00:00:00 2001 From: aamott <54421854+aamott@users.noreply.github.com> Date: Sat, 17 Oct 2026 11:48:23 -0600 Subject: [PATCH 8/9] Align editor header bars with the popout header height The breadcrumb/save strip and the settings bar used a content-driven min-h-8 while the popout headers beside them are fixed h-9, so the two rows next to each other never agreed. Both bars are h-9 now. --- apps/desktop/src/settings/SettingsHeaderBar.tsx | 2 +- apps/desktop/src/shell/WorkspaceHeaderBar.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/settings/SettingsHeaderBar.tsx b/apps/desktop/src/settings/SettingsHeaderBar.tsx index 8fb95b4b..7da2e121 100644 --- a/apps/desktop/src/settings/SettingsHeaderBar.tsx +++ b/apps/desktop/src/settings/SettingsHeaderBar.tsx @@ -150,7 +150,7 @@ export function SettingsHeaderBar({ return (
diff --git a/apps/desktop/src/shell/WorkspaceHeaderBar.tsx b/apps/desktop/src/shell/WorkspaceHeaderBar.tsx index a4ed008a..ff4c5d5d 100644 --- a/apps/desktop/src/shell/WorkspaceHeaderBar.tsx +++ b/apps/desktop/src/shell/WorkspaceHeaderBar.tsx @@ -89,7 +89,7 @@ export function WorkspaceHeaderBar({ return (
From 64dc21bcedb43361a7ea8dbcbe17a87cde6567e6 Mon Sep 17 00:00:00 2001 From: aamott <54421854+aamott@users.noreply.github.com> Date: Sat, 17 Oct 2026 11:51:15 -0600 Subject: [PATCH 9/9] Un-export TabCloseScope to satisfy knip The scope union is only consumed inside tabClose.ts; the exported type read as dead surface in CI's knip check. --- apps/desktop/src/tabs/tabClose.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/desktop/src/tabs/tabClose.ts b/apps/desktop/src/tabs/tabClose.ts index f2d2fb34..0599e70d 100644 --- a/apps/desktop/src/tabs/tabClose.ts +++ b/apps/desktop/src/tabs/tabClose.ts @@ -2,7 +2,7 @@ import { activateExistingTab, removeTab } from "./tabHistory"; import type { DesktopTabState } from "./tabModel"; /** Which neighbours of `tabId` a multi-close targets. */ -export type TabCloseScope = "others" | "right"; +type TabCloseScope = "others" | "right"; export interface TabCloseMultipleAction { readonly type: "closeMultiple";