(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";