Skip to content

The agent that grows with you

fix(desktop): a lone chat keeps its tab strip while another chat zone is open

Austin Pickett36010d0bba66
diff --git a/apps/desktop/src/components/pane-shell/tree/lone-chat-sibling-zone.test.ts b/apps/desktop/src/components/pane-shell/tree/lone-chat-sibling-zone.test.ts
new file mode 100644
index 00000000000..aadb3303a3b
--- /dev/null
+++ b/apps/desktop/src/components/pane-shell/tree/lone-chat-sibling-zone.test.ts
@@ -0,0 +1,58 @@
+import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+
+import { registry } from '@/contrib/registry'
+
+import { findGroupOfPane, group } from './model'
+import {
+ $dismissedPanes,
+ $hiddenTreePanes,
+ $layoutTree,
+ moveTreePane,
+ removeTreePane,
+ tabStripVisibleForGroup
+} from './store'
+
+// The report: two session tabs in main, drag the second one to the right edge,
+// and "the tabs disappear". Main was left a lone uncloseable workspace, which
+// auto treated as "not a tab" — while the tile it had just split from kept its
+// own strip. Pins the store's answer (the one ⌘⌥T toggles against) across the
+// whole gesture and its undo.
+
+const disposers: (() => void)[] = []
+
+beforeEach(() => {
+ window.localStorage.clear()
+ $dismissedPanes.set(new Set())
+ $hiddenTreePanes.set(new Set())
+
+ for (const [id, data] of [
+ ['workspace', { placement: 'main', uncloseable: true }],
+ ['session-tile:b', { placement: 'main' }]
+ ] as const) {
+ disposers.push(registry.register({ area: 'panes', data, id, render: () => null, title: id }))
+ }
+
+ $layoutTree.set(group(['workspace', 'session-tile:b'], { active: 'session-tile:b', id: 'grp-main' }))
+})
+
+afterEach(() => disposers.splice(0).forEach(dispose => dispose()))
+
+const zoneOf = (paneId: string) => findGroupOfPane($layoutTree.get()!, paneId)!
+
+describe('dragging a session tab into its own zone', () => {
+ it('leaves BOTH chat zones with a strip, and main chromeless again once the tile is gone', () => {
+ expect(tabStripVisibleForGroup(zoneOf('workspace'))).toBe(true)
+
+ moveTreePane('session-tile:b', { groupId: 'grp-main', pos: 'right' })
+
+ expect(zoneOf('workspace').id).not.toBe(zoneOf('session-tile:b').id)
+ expect(tabStripVisibleForGroup(zoneOf('workspace'))).toBe(true)
+ expect(tabStripVisibleForGroup(zoneOf('session-tile:b'))).toBe(true)
+ // Nothing was written to the zone to get there — it is still on auto.
+ expect(zoneOf('workspace').tabStrip).toBeUndefined()
+
+ removeTreePane('session-tile:b')
+
+ expect(tabStripVisibleForGroup(zoneOf('workspace'))).toBe(false)
+ })
+})
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/strip-visibility.test.ts b/apps/desktop/src/components/pane-shell/tree/renderer/strip-visibility.test.ts
index c12973042fe..7a874a8b4c9 100644
--- a/apps/desktop/src/components/pane-shell/tree/renderer/strip-visibility.test.ts
+++ b/apps/desktop/src/components/pane-shell/tree/renderer/strip-visibility.test.ts
@@ -85,6 +85,22 @@ describe('a full-page view', () => {
})
})
+// Dragging a session out of the chat strip into its own zone left main a lone
+// workspace: the tile kept its tab (stranded), main lost its tab and its "+",
+// and the two chats side by side read as "the tabs disappeared". Tiles are a
+// tabbed workflow — a main zone keeps its strip while another main zone exists.
+describe('a lone main tile beside another main zone', () => {
+ it('keeps its strip on auto, and only on auto', () => {
+ expect(resolveTabStripVisible({ shown: [workspace()], siblingMainZone: true })).toBe(true)
+ // The whole-window chat is still chromeless, and standing side chrome
+ // never joins the tabbed workflow.
+ expect(resolveTabStripVisible({ shown: [workspace()], siblingMainZone: false })).toBe(false)
+ expect(resolveTabStripVisible({ shown: [sideChrome()], siblingMainZone: true })).toBe(false)
+ // Hide tabs (menu row / ⌘⌥T) still wins — the workspace strands nothing.
+ expect(resolveTabStripVisible({ mode: 'never', shown: [workspace()], siblingMainZone: true })).toBe(false)
+ })
+})
+
// The adapter both TreeGroup and the store call. Its job is to read the same
// chrome flags and fold in the app-wide default on both paths, so the strip on
// screen and the toggle command can never disagree.
@@ -107,7 +123,8 @@ describe('tabStripVisibleForZone', () => {
isCollapsePane: id => id === 'terminal',
mode,
paneFor: id => contributions[id],
- shown
+ shown,
+ siblingMainZone: false
})
afterEach(() => setTabStripDefault('auto'))
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/strip-visibility.ts b/apps/desktop/src/components/pane-shell/tree/renderer/strip-visibility.ts
index 573e8a9879a..7c6242890fa 100644
--- a/apps/desktop/src/components/pane-shell/tree/renderer/strip-visibility.ts
+++ b/apps/desktop/src/components/pane-shell/tree/renderer/strip-visibility.ts
@@ -34,6 +34,9 @@ export interface StripZone {
/** Panes currently rendered as chips — chrome-hidden and narrow-collapsed
* panes are already filtered out. */
shown: readonly StripPane[]
+ /** ANOTHER zone in the layout also hosts a main tile (a chat, a page, a
+ * preview). Auto reads it as "the user is working in tiles". */
+ siblingMainZone?: boolean
}
/**
@@ -89,7 +92,17 @@ export function resolveTabStripVisible(zone: StripZone): boolean {
// Auto: a lone pane is not a "tab", so it goes without a strip; two or more
// need one to switch between them.
- return zone.shown.length > 1
+ if (zone.shown.length > 1) {
+ return true
+ }
+
+ // …except a lone MAIN tile once a second main zone exists. Dragging a
+ // session out of the chat strip into its own zone left the workspace alone
+ // in main: the tile kept its tab (stranded), main lost its tab and its "+",
+ // and two chats side by side read as "my tabs disappeared". Tiles are a
+ // tabbed workflow, so every main zone keeps its strip while there is more
+ // than one; a chat that is the whole window is still chromeless.
+ return Boolean(zone.siblingMainZone) && zone.shown.some(pane => pane.placement === 'main')
}
/**
@@ -107,10 +120,13 @@ export function tabStripVisibleForZone(zone: {
paneFor: (id: string) => Contribution | undefined
/** Panes currently rendered as chips. */
shown: readonly string[]
+ /** Another zone in the layout hosts a main tile too (`$mainTileZoneCount`). */
+ siblingMainZone: boolean
}): boolean {
return resolveTabStripVisible({
headerVeto: paneChrome(zone.paneFor(zone.active)).headerVeto,
mode: effectiveTabStripMode(zone.mode),
+ siblingMainZone: zone.siblingMainZone,
shown: zone.shown.map(id => {
const chrome = paneChrome(zone.paneFor(id))
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx
index c33a8e37366..469f129df55 100644
--- a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx
+++ b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx
@@ -48,6 +48,7 @@ import type { DropPosition, GroupNode } from '../model'
import {
$dropHint,
$hiddenTreePanes,
+ $mainTileZoneCount,
$narrowViewport,
$newSessionTabAction,
$panesWithCloser,
@@ -258,6 +259,9 @@ export function TreeGroup({
const hiddenPanes = useStore($hiddenTreePanes)
const narrow = useStore($narrowViewport)
+ // A count that moves only when a main zone appears or goes — NOT the tree
+ // itself (see the note above `targetPane` on why zones never subscribe to it).
+ const mainTileZoneCount = useStore($mainTileZoneCount)
const workspaceMode = useStore($workspaceMode)
const workspaceOwnerKey = useStore($workspaceOwnerKey)
const newSessionTabAction = useStore($newSessionTabAction)
@@ -342,7 +346,8 @@ export function TreeGroup({
isCollapsePane,
mode: node.tabStrip,
paneFor,
- shown
+ shown,
+ siblingMainZone: mainTileZoneCount > (shown.some(id => paneChrome(paneFor(id)).placement === 'main') ? 1 : 0)
})
// A group collapses ALONG its parent split's axis. In a row that means the
diff --git a/apps/desktop/src/components/pane-shell/tree/store.ts b/apps/desktop/src/components/pane-shell/tree/store.ts
index aa2ce6748b4..170e3a0e666 100644
--- a/apps/desktop/src/components/pane-shell/tree/store.ts
+++ b/apps/desktop/src/components/pane-shell/tree/store.ts
@@ -8,7 +8,7 @@ import { atom, computed, type ReadableAtom } from 'nanostores'
import { SIDEBAR_COLLAPSE_MEDIA_QUERY } from '@/app/layout-constants'
import { setPluginEnabled } from '@/contrib/plugins-store'
-import { registry } from '@/contrib/registry'
+import { $registryVersion, registry } from '@/contrib/registry'
import { translateNow } from '@/i18n'
import { readJson, readKey, writeJson, writeKey } from '@/lib/storage'
import { notify } from '@/store/notifications'
@@ -730,7 +730,7 @@ export const $newSessionTabAction = atom<(() => void) | null>(null)
* the raw array made ⌘2 land on what the strip called tab 1 after a hidden
* pane sat earlier in the list (classic after-⌘W-shift offset).
*/
-function shownPanesInGroup(group: { panes: readonly string[] }): string[] {
+export function shownPanesInGroup(group: { panes: readonly string[] }): string[] {
const hidden = $hiddenTreePanes.get()
const registered = registry.getArea('panes')
const paneFor = (id: string) => registered.find(c => c.id === id)
@@ -760,19 +760,36 @@ function shownPanesInGroup(group: { panes: readonly string[] }): string[] {
})
}
+/** How many zones currently show a MAIN tile (a chat, a page, a preview). A
+ * count, not a list, so it notifies only when a main zone appears or goes —
+ * every TreeGroup reads it, and a sash drag rewrites the tree once per frame.
+ * Registry-versioned because a freshly adopted session tile is in the tree
+ * before its contribution registers `placement: 'main'`. */
+export const $mainTileZoneCount = computed(
+ [$layoutTree, $hiddenTreePanes, $registryVersion],
+ (tree: LayoutNode | null) =>
+ tree
+ ? groupLeafIds(tree).filter(id =>
+ shownPanesInGroup({ panes: findGroup(tree, id)?.panes ?? [] }).some(isMainStripPane)
+ ).length
+ : 0
+)
+
/** Is this zone showing a tab strip right now? The store's adapter over the
* shared resolver — TreeGroup answers the same question from its own render
* inputs, so the toggle command and the strip on screen cannot disagree about
* which way "toggle" points. */
export function tabStripVisibleForGroup(group: GroupNode): boolean {
const registered = registry.getArea('panes')
+ const shown = shownPanesInGroup(group)
return tabStripVisibleForZone({
active: group.active,
isCollapsePane,
mode: group.tabStrip,
paneFor: (id: string) => registered.find(c => c.id === id),
- shown: shownPanesInGroup(group)
+ shown,
+ siblingMainZone: $mainTileZoneCount.get() > (shown.some(isMainStripPane) ? 1 : 0)
})
}