feat(terminal): list terminal tabs in a sheet on portrait phones

On a portrait phone the terminal tab strip shared its row with the
new-tab button and four actions, leaving room for about one squeezed tab
whose always-visible close button sat where a tap to switch lands. With
three tabs, switching became hard and closing a tab by accident easy.

Below 640px on a phone, outside the tablet layout, the header now shows
one trigger with the active tab's icon, name, a tab count and a chevron.
It opens a bottom sheet listing every tab with its full name, rename and
close, plus a row for a new tab. Landscape phones and tablets keep the
strip. The strip, new-tab button and sheet moved into TerminalTabsBar.

Tested in an isolated dev instance at 390x844 with touch emulation:
creating, closing, selecting and renaming tabs, a long name, rotation to
844x390 and a 600x960 tablet keeping the strip, Arabic and light theme.
This commit is contained in:
Bohdan Triapitsyn committed 2026-11-21 21:15:16 +02:00
1 parent 4f2b563a63
commit ad1e4ded1f
19 files changed
+236 -29

No files matched your search

@@ -2,7 +2,7 @@
## Ownership
This module owns the React terminal viewport, chunk replay selection, and tab rename dialog. The viewport connects terminal state and host clipboard actions to the emulator. The [Ghostty adapter](../../lib/ghostty/DOCUMENTATION.md) owns VT parsing, rendering, input encoding, and DOM measurement; the terminal store owns PTY state.
This module owns the React terminal viewport, chunk replay selection, the tab rename dialog, and the tab bar with its phone sheet. The viewport connects terminal state and host clipboard actions to the emulator. The [Ghostty adapter](../../lib/ghostty/DOCUMENTATION.md) owns VT parsing, rendering, input encoding, and DOM measurement; the terminal store owns PTY state.
## Invariants
@@ -24,6 +24,10 @@ The Ghostty adapter loads on demand so the bottom dock can import `TerminalView`
The bundled monospace face normally loads immediately, but a stalled fetch must leave the terminal usable. After 2000 ms the surface can measure available faces; `document.fonts` sends `loadingdone` when a late face arrives so the adapter can refit.
### Why a portrait phone lists tabs in a sheet and not in the strip
On a portrait phone the strip shares its row with new-tab and four actions, which leaves room for about one squeezed tab, and the always-visible close buttons sit where a tap meant to switch lands. On a phone narrower than 640px, outside the tablet layout, the header shows one trigger naming the active tab with a count, and a bottom sheet lists every tab with its full name, rename and close. A phone in landscape and a tablet have the width for the strip and keep it.
### Why theme and font updates reuse the surface and not recreate it
The surface persists for the mounted container and factory so configuration updates preserve the live terminal. Theme and font changes apply in place.
@@ -0,0 +1,91 @@
import React from 'react';
import { Icon } from '@/components/icon/Icon';
import { ButtonTooltip } from '@/components/ui/action-toolbar';
import { Button } from '@/components/ui/button';
import { SortableTabsStrip, type SortableTabsStripItem } from '@/components/ui/sortable-tabs-strip';
import { useDeviceInfo, useTabletLayout } from '@/lib/device';
import { useI18n } from '@/lib/i18n';
import { cn } from '@/lib/utils';
import { TerminalTabsSheet } from './TerminalTabsSheet';
type StripProps = React.ComponentProps<typeof SortableTabsStrip>;
type TerminalTabsBarProps = {
tabs: Array<SortableTabsStripItem & { icon: React.ReactNode; renamable: boolean }>;
activeId: string | null;
inPanelHeader: boolean;
onSelect: (tabId: string) => void;
onClose: (tabId: string) => void;
onReorder: (tabId: string, overTabId: string) => void;
onRename: (tabId: string) => void;
onCreate: () => void;
tabContextMenu: StripProps['tabContextMenu'];
onTabDragOut: StripProps['onTabDragOut'];
};
const PHONE_PORTRAIT_MAX_WIDTH = 640;
export const TerminalTabsBar: React.FC<TerminalTabsBarProps> = ({
tabs,
activeId,
inPanelHeader,
onSelect,
onClose,
onReorder,
onRename,
onCreate,
tabContextMenu,
onTabDragOut,
}) => {
const { t } = useI18n();
const { isMobile, isTablet, screenWidth } = useDeviceInfo();
const tabletLayout = useTabletLayout().enabled;
const isTouch = isMobile || isTablet;
if (isMobile && !tabletLayout && screenWidth < PHONE_PORTRAIT_MAX_WIDTH) {
return (
<div className="flex min-w-0 flex-1 items-center">
<TerminalTabsSheet
tabs={tabs}
activeId={activeId}
onSelect={onSelect}
onClose={onClose}
onRename={onRename}
onCreate={onCreate}
/>
</div>
);
}
return (
<>
<div className={cn('min-w-0 flex-1', inPanelHeader ? 'self-stretch' : isTouch ? 'h-8' : 'h-7')}>
<SortableTabsStrip
items={tabs}
activeId={activeId}
onSelect={onSelect}
onClose={onClose}
onReorder={onReorder}
tabContextMenu={tabContextMenu}
onTabDragOut={onTabDragOut}
layoutMode="scrollable"
variant="default"
className="h-full bg-transparent"
/>
</div>
<ButtonTooltip label={t('contextTooltips.terminalBrowser.terminal.newTab')} side="bottom" className="shrink-0">
<Button
type="button"
size="xs"
variant="ghost"
className={cn('shrink-0', isTouch ? 'h-8 w-8 p-0' : 'h-7 w-7 p-0')}
onClick={onCreate}
aria-label={t('contextTooltips.terminalBrowser.terminal.newTab')}
>
<Icon name="add" className={isTouch ? 'h-[18px] w-[18px]' : 'h-4 w-4'} />
</Button>
</ButtonTooltip>
</>
);
};
@@ -0,0 +1,111 @@
import React from 'react';
import { Icon } from '@/components/icon/Icon';
import { Button } from '@/components/ui/button';
import { MobileOverlayPanel } from '@/components/ui/MobileOverlayPanel';
import { MobileSheetRow } from '@/components/ui/MobileSheetList';
import { useI18n } from '@/lib/i18n';
type TerminalSheetTab = {
id: string;
label: string;
icon: React.ReactNode;
renamable: boolean;
};
type TerminalTabsSheetProps = {
tabs: TerminalSheetTab[];
activeId: string | null;
onSelect: (tabId: string) => void;
onClose: (tabId: string) => void;
onRename: (tabId: string) => void;
onCreate: () => void;
};
const ROW_ACTION_CLASS = 'h-9 w-9 p-0 text-muted-foreground';
export const TerminalTabsSheet: React.FC<TerminalTabsSheetProps> = ({ tabs, activeId, onSelect, onClose, onRename, onCreate }) => {
const { t } = useI18n();
const [open, setOpen] = React.useState(false);
const activeTab = tabs.find((tab) => tab.id === activeId) ?? tabs[0];
const dismiss = React.useCallback(() => setOpen(false), []);
return (
<>
<button
type="button"
aria-haspopup="dialog"
aria-expanded={open}
onClick={() => setOpen(true)}
className="flex h-8 min-w-0 max-w-full items-center gap-1.5 rounded-md px-2 text-foreground touch-manipulation active:bg-interactive-hover"
>
{activeTab ? <span className="flex shrink-0 items-center">{activeTab.icon}</span> : null}
<span dir="auto" className="min-w-0 truncate typography-ui-label">{activeTab?.label ?? t('terminalView.tabs.sheetTitle')}</span>
{tabs.length > 1 ? (
<span className="flex h-5 min-w-5 shrink-0 items-center justify-center rounded-md bg-interactive-hover px-1 typography-micro font-medium text-foreground tabular-nums">
{tabs.length}
</span>
) : null}
<Icon name="arrow-down-s" className="size-4 shrink-0 text-muted-foreground" />
</button>
<MobileOverlayPanel
open={open && tabs.length > 0}
title={t('terminalView.tabs.sheetTitle')}
onClose={dismiss}
footer={(
<MobileSheetRow
icon="add"
onClick={() => {
dismiss();
onCreate();
}}
>
{t('contextTooltips.terminalBrowser.terminal.newTab')}
</MobileSheetRow>
)}
>
{tabs.map((tab) => (
<MobileSheetRow
key={tab.id}
selected={tab.id === activeTab?.id}
leading={<span className="flex shrink-0 items-center">{tab.icon}</span>}
onClick={() => {
dismiss();
onSelect(tab.id);
}}
action={(
<>
{tab.renamable ? (
<Button
type="button"
variant="ghost"
size="icon"
className={ROW_ACTION_CLASS}
aria-label={t('terminalView.tabs.menu.rename')}
onClick={() => {
dismiss();
onRename(tab.id);
}}
>
<Icon name="edit" className="size-4" />
</Button>
) : null}
<Button
type="button"
variant="ghost"
size="icon"
className={ROW_ACTION_CLASS}
aria-label={t('terminalView.tabs.closeTabTitle')}
onClick={() => onClose(tab.id)}
>
<Icon name="close" className="size-4" />
</Button>
</>
)}
>
<span dir="auto">{tab.label}</span>
</MobileSheetRow>
))}
</MobileOverlayPanel>
</>
);
};
@@ -24,9 +24,9 @@ import { Button } from '@/components/ui/button';
import { ButtonTooltip } from '@/components/ui/action-toolbar';
import { toast } from '@/components/ui';
import { copyTextToClipboard } from '@/lib/clipboard';
import { SortableTabsStrip } from '@/components/ui/sortable-tabs-strip';
import { ContextMenuItem, ContextMenuSeparator } from '@/components/ui/context-menu';
import { TerminalTabRenameDialog } from '@/components/terminal/TerminalTabRenameDialog';
import { TerminalTabsBar } from '@/components/terminal/TerminalTabsBar';
import { Icon } from "@/components/icon/Icon";
import type { IconName } from '@/components/icon/icons';
import { useDeviceInfo } from '@/lib/device';
@@ -188,6 +188,7 @@ export const TerminalView: React.FC<TerminalViewProps> = ({ visible, directory,
label: tab.label,
title: tab.label,
closeLabel: t('terminalView.tabs.closeTabTitle'),
renamable: tab.purpose.type === 'terminal',
}));
}, [directoryTerminalState?.tabs, t]);
@@ -1326,33 +1327,18 @@ export const TerminalView: React.FC<TerminalViewProps> = ({ visible, directory,
{enableTabs && directoryTerminalState ? (
<ContextPanelHeaderToolbar>
<div className={cn('app-region-no-drag flex min-w-0 items-center gap-2 text-xs', inPanelHeader ? 'flex-1 pe-1' : cn('sticky top-0 z-20 shrink-0 bg-[var(--surface-background)]', isTouchTerminal ? 'px-4 py-1.5' : 'ps-4 pe-2.5 py-1'))}>
<div className={cn('min-w-0 flex-1', inPanelHeader ? 'self-stretch' : isTouchTerminal ? 'h-8' : 'h-7')}>
<SortableTabsStrip
items={terminalTabItems}
activeId={activeTabId}
onSelect={handleSelectTab}
onClose={handleCloseTab}
onReorder={handleReorderTab}
tabContextMenu={renderTabContextMenu}
onTabDragOut={handleTabDragOut}
layoutMode="scrollable"
variant="default"
className="h-full bg-transparent"
/>
</div>
<ButtonTooltip label={t('contextTooltips.terminalBrowser.terminal.newTab')} side="bottom" className="shrink-0">
<Button
type="button"
size="xs"
variant="ghost"
className={cn('shrink-0', isTouchTerminal ? 'h-8 w-8 p-0' : 'h-7 w-7 p-0')}
onClick={handleCreateTab}
aria-label={t('contextTooltips.terminalBrowser.terminal.newTab')}
>
<Icon name="add" className={`${isTouchTerminal ? 'h-[18px] w-[18px]' : 'h-4 w-4'}`}/>
</Button>
</ButtonTooltip>
<TerminalTabsBar
tabs={terminalTabItems}
activeId={activeTabId}
inPanelHeader={inPanelHeader}
onSelect={handleSelectTab}
onClose={handleCloseTab}
onReorder={handleReorderTab}
onRename={setRenamingTabId}
onCreate={handleCreateTab}
tabContextMenu={renderTabContextMenu}
onTabDragOut={handleTabDragOut}
/>
<div className="flex shrink-0 items-center gap-1 overflow-visible">
<ButtonTooltip label={t('terminalView.actions.restart')} side="bottom">
+1
View File
@@ -2176,6 +2176,7 @@ export const dict: Record<I18nKey, string> = {
'terminalView.quickKeys.enterAria': 'Enter',
'terminalView.tabs.closeTabTitle': 'إغلاق علامة التبويب',
'terminalView.tabs.newTabTitle': 'علامة تبويب جديدة',
'terminalView.tabs.sheetTitle': 'الطرفيات',
'terminalView.tabs.menu.rename': 'إعادة تسمية',
'terminalView.tabs.renameDialog.title': 'إعادة تسمية الطرفية',
'terminalView.tabs.renameDialog.placeholder': 'اسم الطرفية',
+1
View File
@@ -2010,6 +2010,7 @@ export const dict = {
'terminalView.quickKeys.enterAria': 'Enter',
'terminalView.tabs.closeTabTitle': 'Registerkarte schließen',
'terminalView.tabs.newTabTitle': 'Neue Registerkarte',
'terminalView.tabs.sheetTitle': 'Terminals',
'terminalView.tabs.menu.rename': 'Umbenennen',
'terminalView.tabs.renameDialog.title': 'Terminal umbenennen',
'terminalView.tabs.renameDialog.placeholder': 'Terminalname',
+1
View File
@@ -2277,6 +2277,7 @@ export const dict = {
'terminalView.quickKeys.enterAria': 'Enter',
'terminalView.tabs.closeTabTitle': 'Close tab',
'terminalView.tabs.newTabTitle': 'New tab',
'terminalView.tabs.sheetTitle': 'Terminals',
'terminalView.tabs.menu.rename': 'Rename',
'terminalView.tabs.renameDialog.title': 'Rename terminal',
'terminalView.tabs.renameDialog.placeholder': 'Terminal name',
+1
View File
@@ -2245,6 +2245,7 @@ export const dict: Record<I18nKey, string> = {
"terminalView.quickKeys.enterAria": "Enter",
"terminalView.tabs.closeTabTitle": "Cerrar pestaña",
"terminalView.tabs.newTabTitle": "Nueva pestaña",
"terminalView.tabs.sheetTitle": "Terminales",
"terminalView.tabs.menu.rename": "Renombrar",
"terminalView.tabs.renameDialog.title": "Renombrar terminal",
"terminalView.tabs.renameDialog.placeholder": "Nombre del terminal",
+1
View File
@@ -2022,6 +2022,7 @@ export const dict = {
'terminalView.quickKeys.enterAria': 'Entrée',
'terminalView.tabs.closeTabTitle': 'Fermer l\'onglet',
'terminalView.tabs.newTabTitle': 'Nouvel onglet',
'terminalView.tabs.sheetTitle': 'Terminaux',
'terminalView.tabs.menu.rename': 'Renommer',
'terminalView.tabs.renameDialog.title': 'Renommer le terminal',
'terminalView.tabs.renameDialog.placeholder': 'Nom du terminal',
+1
View File
@@ -2175,6 +2175,7 @@ export const dict = {
'terminalView.quickKeys.enterAria': 'Enter',
'terminalView.tabs.closeTabTitle': 'סגור כרטיסייה',
'terminalView.tabs.newTabTitle': 'כרטיסייה חדשה',
'terminalView.tabs.sheetTitle': 'מסופים',
'terminalView.tabs.menu.rename': 'שנה שם',
'terminalView.tabs.renameDialog.title': 'שינוי שם המסוף',
'terminalView.tabs.renameDialog.placeholder': 'שם המסוף',
+1
View File
@@ -2273,6 +2273,7 @@ export const dict: Record<I18nKey, string> = {
'terminalView.quickKeys.enterAria': 'Enter',
'terminalView.tabs.closeTabTitle': 'タブを閉じる',
'terminalView.tabs.newTabTitle': '新しいタブ',
'terminalView.tabs.sheetTitle': 'ターミナル',
'terminalView.tabs.menu.rename': '名前を変更',
'terminalView.tabs.renameDialog.title': 'ターミナル名を変更',
'terminalView.tabs.renameDialog.placeholder': 'ターミナル名',
+1
View File
@@ -2277,6 +2277,7 @@ export const dict: Record<I18nKey, string> = {
'terminalView.quickKeys.enterAria': 'Enter',
'terminalView.tabs.closeTabTitle': '탭 닫기',
'terminalView.tabs.newTabTitle': '새 탭',
'terminalView.tabs.sheetTitle': '터미널',
'terminalView.tabs.menu.rename': '이름 바꾸기',
'terminalView.tabs.renameDialog.title': '터미널 이름 바꾸기',
'terminalView.tabs.renameDialog.placeholder': '터미널 이름',
+1
View File
@@ -2277,6 +2277,7 @@ export const dict = {
'terminalView.quickKeys.enterAria': 'Enter',
'terminalView.tabs.closeTabTitle': 'Tabblad sluiten',
'terminalView.tabs.newTabTitle': 'Nieuw tabblad',
'terminalView.tabs.sheetTitle': 'Terminals',
'terminalView.tabs.menu.rename': 'Hernoemen',
'terminalView.tabs.renameDialog.title': 'Terminal hernoemen',
'terminalView.tabs.renameDialog.placeholder': 'Terminalnaam',
+1
View File
@@ -3503,6 +3503,7 @@ export const dict: Record<I18nKey, string> = {
'terminalView.stream.processExitedWithSignal': ' (signal {signal})',
'terminalView.tabs.closeTabTitle': 'Close tab',
'terminalView.tabs.newTabTitle': 'Nowa karta',
'terminalView.tabs.sheetTitle': 'Terminale',
'terminalView.tabs.menu.rename': 'Zmień nazwę',
'terminalView.tabs.renameDialog.title': 'Zmień nazwę terminala',
'terminalView.tabs.renameDialog.placeholder': 'Nazwa terminala',
@@ -2245,6 +2245,7 @@ export const dict: Record<I18nKey, string> = {
"terminalView.quickKeys.enterAria": "Enter",
"terminalView.tabs.closeTabTitle": "Fechar aba",
"terminalView.tabs.newTabTitle": "Nova aba",
"terminalView.tabs.sheetTitle": "Terminais",
"terminalView.tabs.menu.rename": "Renomear",
"terminalView.tabs.renameDialog.title": "Renomear terminal",
"terminalView.tabs.renameDialog.placeholder": "Nome do terminal",
+1
View File
@@ -2145,6 +2145,7 @@ export const dict = {
'terminalView.quickKeys.enterAria': 'Enter',
'terminalView.tabs.closeTabTitle': 'Sekmeyi kapat',
'terminalView.tabs.newTabTitle': 'Yeni sekme',
'terminalView.tabs.sheetTitle': 'Terminaller',
'terminalView.tabs.menu.rename': 'Yeniden adlandır',
'terminalView.tabs.renameDialog.title': 'Terminali yeniden adlandır',
'terminalView.tabs.renameDialog.placeholder': 'Terminal adı',
+1
View File
@@ -2245,6 +2245,7 @@ export const dict: Record<I18nKey, string> = {
"terminalView.quickKeys.enterAria": "Enter",
"terminalView.tabs.closeTabTitle": "Закрити вкладку",
"terminalView.tabs.newTabTitle": "Нова вкладка",
"terminalView.tabs.sheetTitle": "Термінали",
"terminalView.tabs.menu.rename": "Перейменувати",
"terminalView.tabs.renameDialog.title": "Перейменувати термінал",
"terminalView.tabs.renameDialog.placeholder": "Назва термінала",
@@ -2243,6 +2243,7 @@ export const dict: Record<I18nKey, string> = {
'terminalView.quickKeys.enterAria': 'Enter 键',
'terminalView.tabs.closeTabTitle': '关闭标签页',
'terminalView.tabs.newTabTitle': '新建标签页',
'terminalView.tabs.sheetTitle': '终端',
'terminalView.tabs.menu.rename': '重命名',
'terminalView.tabs.renameDialog.title': '重命名终端',
'terminalView.tabs.renameDialog.placeholder': '终端名称',
@@ -2254,6 +2254,7 @@ export const dict: Record<I18nKey, string> = {
'terminalView.quickKeys.enterAria': 'Enter 鍵',
'terminalView.tabs.closeTabTitle': '關閉分頁',
'terminalView.tabs.newTabTitle': '新增分頁',
'terminalView.tabs.sheetTitle': '終端',
'terminalView.tabs.menu.rename': '重新命名',
'terminalView.tabs.renameDialog.title': '重新命名終端機',
'terminalView.tabs.renameDialog.placeholder': '終端機名稱',