From eb545ddea9f5b6b59011eef0e743ca1be826b1f1 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Sat, 1 Aug 2026 02:15:02 -0500 Subject: [PATCH] =?UTF-8?q?feat(desktop):=20=E2=8C=98-click=20closes=20a?= =?UTF-8?q?=20terminal=20rail=20tab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same gesture the pane tabs already carry — isMetaClose hoists from pane-tab.tsx into lib/middle-click.ts beside its sibling middle-click gesture, so the two surfaces share one predicate instead of drifting. --- .../src/app/right-sidebar/terminal/rail.test.tsx | 16 ++++++++++++++++ .../src/app/right-sidebar/terminal/rail.tsx | 5 +++-- apps/desktop/src/components/ui/pane-tab.tsx | 8 +------- apps/desktop/src/lib/middle-click.ts | 6 ++++++ 4 files changed, 26 insertions(+), 9 deletions(-) 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 60b2113916..baf5874bb3 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() + + 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 7b5aee0ffa..d5e654b31b 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 87545f018c..47aad2614d 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 bba5e58743..5d31cdac13 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