Skip to content

The agent that grows with you

feat(desktop): ⌘-click closes a terminal rail tab

Brooklyn Nicholsoneb545ddea9f5
diff --git a/apps/desktop/src/app/right-sidebar/terminal/rail.test.tsx b/apps/desktop/src/app/right-sidebar/terminal/rail.test.tsx
index 60b2113916a..baf5874bb3e 100644
--- a/apps/desktop/src/app/right-sidebar/terminal/rail.test.tsx
+++ b/apps/desktop/src/app/right-sidebar/terminal/rail.test.tsx
@@ -33,4 +33,20 @@ describe('TerminalRail', () => {
expect(label?.classList.contains('inline-flex')).toBe(true)
expect(label?.classList.contains('flex')).toBe(false)
})
+
+ it('⌘-click closes the tab; a plain click selects it', () => {
+ $terminals.set([
+ ...$terminals.get(),
+ { auto: true, cwd: 'C:\\repo', id: 'term-2', kind: 'user', title: 'zsh' }
+ ])
+
+ render(<TerminalRail />)
+
+ fireEvent.click(screen.getByRole('tab', { name: '2. zsh' }), { metaKey: true })
+ expect($terminals.get().map(term => term.id)).toEqual(['term-1'])
+
+ fireEvent.click(screen.getByRole('tab', { name: '1. PowerShell' }))
+ expect($activeTerminalId.get()).toBe('term-1')
+ expect($terminals.get()).toHaveLength(1)
+ })
})
diff --git a/apps/desktop/src/app/right-sidebar/terminal/rail.tsx b/apps/desktop/src/app/right-sidebar/terminal/rail.tsx
index 7b5aee0ffa3..d5e654b31b0 100644
--- a/apps/desktop/src/app/right-sidebar/terminal/rail.tsx
+++ b/apps/desktop/src/app/right-sidebar/terminal/rail.tsx
@@ -11,7 +11,7 @@ import {
import { Tip, TipHintLabel } from '@/components/ui/tooltip'
import { useI18n } from '@/i18n'
import { formatCombo } from '@/lib/keybinds/combo'
-import { middleClickHandlers } from '@/lib/middle-click'
+import { isMetaClose, middleClickHandlers } from '@/lib/middle-click'
import { cn } from '@/lib/utils'
import { $bindings } from '@/store/keybinds'
@@ -132,7 +132,8 @@ function TerminalRailItem({ active, canCloseOthers, index, term, toggleHint }: T
: 'text-(--ui-text-tertiary) hover:bg-(--chrome-action-hover) hover:text-foreground'
)}
{...middleClickHandlers(() => closeTerminal(term.id))}
- onClick={() => selectTerminal(term.id)}
+ // ⌘-click closes (the pane-tab gesture); a plain click selects.
+ onClick={event => (isMetaClose(event) ? closeTerminal(term.id) : selectTerminal(term.id))}
role="tab"
type="button"
>
diff --git a/apps/desktop/src/components/ui/pane-tab.tsx b/apps/desktop/src/components/ui/pane-tab.tsx
index 87545f018c6..47aad2614df 100644
--- a/apps/desktop/src/components/ui/pane-tab.tsx
+++ b/apps/desktop/src/components/ui/pane-tab.tsx
@@ -1,6 +1,6 @@
import * as React from 'react'
-import { middleClickHandlers } from '@/lib/middle-click'
+import { isMetaClose, middleClickHandlers } from '@/lib/middle-click'
import { cn } from '@/lib/utils'
/** Inset stroke for a vertical tab rail — content-facing edge. */
@@ -43,12 +43,6 @@ interface PaneTabProps extends React.ComponentProps<'div'> {
side?: 'left' | 'right'
}
-/** ⌘-click (metaKey + primary button) — the Mac has no middle button, so this
- * is the trackpad equivalent of middle-click-to-close. Guarded on metaKey so
- * it never collides with left-click (activate/drag) or ⌃-click (macOS context
- * menu). */
-const isMetaClose = (event: { button: number; metaKey: boolean }) => event.button === 0 && event.metaKey
-
/**
* Editor tab shell — preview rail + zone headers + collapsed vertical rails.
*
diff --git a/apps/desktop/src/lib/middle-click.ts b/apps/desktop/src/lib/middle-click.ts
index bba5e587431..5d31cdac132 100644
--- a/apps/desktop/src/lib/middle-click.ts
+++ b/apps/desktop/src/lib/middle-click.ts
@@ -3,6 +3,12 @@ import type * as React from 'react'
/** `MouseEvent.button` for the middle (wheel) button. */
const MIDDLE_BUTTON = 1
+/** ⌘-click (metaKey + primary button) — the Mac has no middle button, so this
+ * is the trackpad equivalent of middle-click-to-close. Guarded on metaKey so
+ * it never collides with left-click (activate/drag) or ⌃-click (macOS context
+ * menu). */
+export const isMetaClose = (event: { button: number; metaKey: boolean }) => event.button === 0 && event.metaKey
+
/** Where the current middle press started. One pointer holds one button, so a
* single slot is the whole state, and it's only ever compared by identity in
* the pointerup right after — a value left behind by a press released