feat(desktop): ⌘-click closes a terminal rail tab
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.
This commit is contained in:
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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"
|
||||
>
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user