The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 05:30 UTC
refactor(web): the terminal drawer keeps its caching without "use memo" (#20799)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 17, 2026 at 00:32 UTC
c60afa29f154a663c620f31138639d1295644f0a
1 file changed
+328
-257
apps/web/src/components/ThreadTerminalDrawer.tsx
+328
-257
@@ -1144,107 +1144,6 @@ interface ThreadTerminalDrawerProps {
1144
terminalLaunchLocationsById?: ReadonlyMap<string, TerminalLaunchLocation>;
1145
}
1146
1147
-function useTerminalLayout(
1148
- terminalIds: readonly string[],
1149
- terminalGroups: readonly ThreadTerminalGroup[],
1150
- terminalLabelsById: ReadonlyMap<string, string> | undefined,
1151
-) {
1152
- // Calls no hooks, so the compiler needs the directive to memoize it.
1153
- "use memo";
1154
- const normalizedTerminalIds = (() => {
1155
- const normalizedIds: string[] = [];
1156
- const seen = new Set<string>();
1157
- for (const id of terminalIds) {
1158
- const trimmedId = id.trim();
1159
- if (trimmedId.length === 0 || seen.has(trimmedId)) continue;
1160
- seen.add(trimmedId);
1161
- normalizedIds.push(trimmedId);
1162
- }
1163
- return normalizedIds;
1164
- })();
1165
- const resolvedTerminalGroups = (() => {
1166
- if (normalizedTerminalIds.length === 0) {
1167
- return [];
1168
- }
1169
- const validTerminalIdSet = new Set(normalizedTerminalIds);
1170
- const assignedTerminalIds = new Set<string>();
1171
- const usedGroupIds = new Set<string>();
1172
- const nextGroups: ThreadTerminalGroup[] = [];
1173
-
1174
- const assignUniqueGroupId = (groupId: string): string => {
1175
- if (!usedGroupIds.has(groupId)) {
1176
- usedGroupIds.add(groupId);
1177
- return groupId;
1178
- }
1179
- let suffix = 2;
1180
- while (usedGroupIds.has(`${groupId}-${suffix}`)) {
1181
- suffix += 1;
1182
- }
1183
- const uniqueGroupId = `${groupId}-${suffix}`;
1184
- usedGroupIds.add(uniqueGroupId);
1185
- return uniqueGroupId;
1186
- };
1187
-
1188
- for (const terminalGroup of terminalGroups) {
1189
- const nextTerminalIds: string[] = [];
1190
- const seenGroupTerminalIds = new Set<string>();
1191
- for (const id of terminalGroup.terminalIds) {
1192
- const terminalId = id.trim();
1193
- if (terminalId.length === 0) continue;
1194
- if (seenGroupTerminalIds.has(terminalId)) continue;
1195
- seenGroupTerminalIds.add(terminalId);
1196
- if (!validTerminalIdSet.has(terminalId)) continue;
1197
- if (assignedTerminalIds.has(terminalId)) continue;
1198
- nextTerminalIds.push(terminalId);
1199
- }
1200
- if (nextTerminalIds.length === 0) continue;
1201
-
1202
- for (const terminalId of nextTerminalIds) {
1203
- assignedTerminalIds.add(terminalId);
1204
- }
1205
-
1206
- const baseGroupId =
1207
- terminalGroup.id.trim().length > 0
1208
- ? terminalGroup.id.trim()
1209
- : `group-${nextTerminalIds[0] ?? normalizedTerminalIds[0] ?? ""}`;
1210
- nextGroups.push({
1211
- id: assignUniqueGroupId(baseGroupId),
1212
- terminalIds: nextTerminalIds,
1213
- ...(terminalGroup.splitDirection === "vertical"
1214
- ? { splitDirection: "vertical" as const }
1215
- : {}),
1216
- });
1217
- }
1218
-
1219
- for (const terminalId of normalizedTerminalIds) {
1220
- if (assignedTerminalIds.has(terminalId)) continue;
1221
- nextGroups.push({
1222
- id: assignUniqueGroupId(`group-${terminalId}`),
1223
- terminalIds: [terminalId],
1224
- });
1225
- }
1226
-
1227
- const terminalOrderIndex = new Map(
1228
- normalizedTerminalIds.map((id, index) => [id, index] as const),
1229
- );
1230
- nextGroups.sort((left, right) => {
1231
- const rank = (ids: readonly string[]) =>
1232
- Math.min(...ids.map((id) => terminalOrderIndex.get(id) ?? Number.POSITIVE_INFINITY));
1233
- return rank(left.terminalIds) - rank(right.terminalIds);
1234
- });
1235
-
1236
- return nextGroups;
1237
- })();
1238
- const terminalLabelById = (() => {
1239
- const next = new Map<string, string>();
1240
- for (const terminalId of normalizedTerminalIds) {
1241
- next.set(terminalId, terminalLabelsById?.get(terminalId) ?? getTerminalLabel(terminalId));
1242
- }
1243
- return next;
1244
- })();
1245
- return { normalizedTerminalIds, resolvedTerminalGroups, terminalLabelById };
1246
-}
1247
-
1147
interface TerminalActionButtonProps {
1148
label: string;
1149
className: string;
@@ -1289,6 +1188,198 @@ function TerminalActionButton({
1188
);
1189
}
1190
1191
+function TerminalSplitPanes({
1192
+ terminalIds,
1193
+ splitDirection,
1194
+ activeTerminalId,
1195
+ terminalLabelById,
1196
+ resolveLaunchLocation,
1197
+ onActiveTerminalChange,
1198
+ onCloseTerminal,
1199
+ advancedTypography,
1200
+ threadRef,
1201
+ threadId,
1202
+ onAddTerminalContext,
1203
+ focusRequestId,
1204
+ visible,
1205
+ resizeEpoch,
1206
+ drawerHeight,
1207
+ keybindings,
1208
+}: {
1209
+ terminalIds: readonly string[];
1210
+ splitDirection: "horizontal" | "vertical";
1211
+ activeTerminalId: string;
1212
+ terminalLabelById: ReadonlyMap<string, string>;
1213
+ resolveLaunchLocation: (terminalId: string) => TerminalLaunchLocation;
1214
+ onActiveTerminalChange: (terminalId: string) => void;
1215
+ onCloseTerminal: (terminalId: string) => void;
1216
+ advancedTypography: boolean;
1217
+ threadRef: ScopedThreadRef;
1218
+ threadId: ThreadId;
1219
+ onAddTerminalContext: (selection: TerminalContextSelection) => void;
1220
+ focusRequestId: number;
1221
+ visible: boolean;
1222
+ resizeEpoch: number;
1223
+ drawerHeight: number;
1224
+ keybindings: ResolvedKeybindingsConfig;
1225
+}) {
1226
+ return (
1227
+ <div
1228
+ className="grid h-full w-full min-w-0 gap-0 overflow-hidden"
1229
+ style={
1230
+ splitDirection === "vertical"
1231
+ ? {
1232
+ gridTemplateRows: `repeat(${terminalIds.length}, minmax(0, 1fr))`,
1233
+ }
1234
+ : {
1235
+ gridTemplateColumns: `repeat(${terminalIds.length}, minmax(0, 1fr))`,
1236
+ }
1237
+ }
1238
+ >
1239
+ {terminalIds.map((terminalId) => {
1240
+ const terminalLaunchLocation = resolveLaunchLocation(terminalId);
1241
+ return (
1242
+ <div
1243
+ key={terminalId}
1244
+ className={`min-h-0 min-w-0 ${
1245
+ splitDirection === "vertical"
1246
+ ? "border-t first:border-t-0"
1247
+ : "border-l first:border-l-0"
1248
+ } ${terminalId === activeTerminalId ? "border-border" : "border-border/70"}`}
1249
+ onPointerDown={() => {
1250
+ if (terminalId !== activeTerminalId) {
1251
+ onActiveTerminalChange(terminalId);
1252
+ }
1253
+ }}
1254
+ >
1255
+ <div className="h-full">
1256
+ <TerminalViewport
1257
+ advancedTypography={advancedTypography}
1258
+ threadRef={threadRef}
1259
+ threadId={threadId}
1260
+ terminalId={terminalId}
1261
+ terminalLabel={terminalLabelById.get(terminalId) ?? "Terminal"}
1262
+ cwd={terminalLaunchLocation.cwd}
1263
+ {...(terminalLaunchLocation.worktreePath !== undefined
1264
+ ? { worktreePath: terminalLaunchLocation.worktreePath }
1265
+ : {})}
1266
+ {...(terminalLaunchLocation.runtimeEnv
1267
+ ? { runtimeEnv: terminalLaunchLocation.runtimeEnv }
1268
+ : {})}
1269
+ onSessionExited={() => onCloseTerminal(terminalId)}
1270
+ onAddTerminalContext={onAddTerminalContext}
1271
+ focusRequestId={focusRequestId}
1272
+ autoFocus={terminalId === activeTerminalId}
1273
+ visible={visible}
1274
+ resizeEpoch={resizeEpoch}
1275
+ drawerHeight={drawerHeight}
1276
+ keybindings={keybindings}
1277
+ />
1278
+ </div>
1279
+ </div>
1280
+ );
1281
+ })}
1282
+ </div>
1283
+ );
1284
+}
1285
+
1286
+function TerminalSidebarGroup({
1287
+ terminalGroup,
1288
+ activeTerminalId,
1289
+ showHeader,
1290
+ terminalLabelById,
1291
+ closeShortcutLabel,
1292
+ canOperateTerminal,
1293
+ onActiveTerminalChange,
1294
+ onCloseTerminal,
1295
+}: {
1296
+ terminalGroup: ThreadTerminalGroup;
1297
+ activeTerminalId: string;
1298
+ showHeader: boolean;
1299
+ terminalLabelById: ReadonlyMap<string, string>;
1300
+ closeShortcutLabel: string | undefined;
1301
+ canOperateTerminal: boolean;
1302
+ onActiveTerminalChange: (terminalId: string) => void;
1303
+ onCloseTerminal: (terminalId: string) => void;
1304
+}) {
1305
+ const isGroupActive = terminalGroup.terminalIds.includes(activeTerminalId);
1306
+ const groupActiveTerminalId = isGroupActive
1307
+ ? activeTerminalId
1308
+ : (terminalGroup.terminalIds[0] ?? activeTerminalId);
1309
+ const terminalCount = terminalGroup.terminalIds.length;
1310
+ const isSplitGroup = terminalCount > 1;
1311
+ const groupLabel = !isSplitGroup
1312
+ ? "Single"
1313
+ : terminalGroup.splitDirection === "vertical"
1314
+ ? "Stacked"
1315
+ : "Side by side";
1316
+ const GroupIcon = !isSplitGroup
1317
+ ? Square
1318
+ : terminalGroup.splitDirection === "vertical"
1319
+ ? SquareSplitVertical
1320
+ : SquareSplitHorizontal;
1321
+
1322
+ return (
1323
+ <div className="pb-0.5">
1324
+ {showHeader && (
1325
+ <button
1326
+ type="button"
1327
+ className={`flex h-[22px] w-full cursor-pointer items-center gap-1 rounded px-1.5 text-2xs ${
1328
+ isGroupActive
1329
+ ? "bg-accent/50 text-foreground"
1330
+ : "text-muted-foreground hover:bg-accent/40 hover:text-foreground"
1331
+ }`}
1332
+ onClick={() => onActiveTerminalChange(groupActiveTerminalId)}
1333
+ >
1334
+ <GroupIcon className="size-3 shrink-0" />
1335
+ <span className="min-w-0 flex-1 truncate text-left">{groupLabel}</span>
1336
+ <span className="text-muted-foreground/70 text-3xs tabular-nums">{terminalCount}</span>
1337
+ </button>
1338
+ )}
1339
+
1340
+ <div className="flex flex-col gap-0.5">
1341
+ {terminalGroup.terminalIds.map((terminalId) => {
1342
+ const isActive = terminalId === activeTerminalId;
1343
+ const terminalLabel = terminalLabelById.get(terminalId) ?? "Terminal";
1344
+ const closeTerminalLabel = `Close ${terminalLabel}${
1345
+ isActive && closeShortcutLabel ? ` (${closeShortcutLabel})` : ""
1346
+ }`;
1347
+ return (
1348
+ <div
1349
+ key={terminalId}
1350
+ className={cn(
1351
+ "group/tab flex h-6 w-full items-center gap-0.5 rounded-md pr-2 pl-1.5 text-xs",
1352
+ isActive
1353
+ ? "bg-accent text-foreground"
1354
+ : "text-muted-foreground hover:bg-accent/60 hover:text-foreground",
1355
+ )}
1356
+ >
1357
+ {canOperateTerminal ? (
1358
+ <PanelTabCloseButton
1359
+ label={closeTerminalLabel}
1360
+ onClick={() => onCloseTerminal(terminalId)}
1361
+ tooltip={closeTerminalLabel}
1362
+ >
1363
+ <TerminalSquare className="size-3 shrink-0" />
1364
+ </PanelTabCloseButton>
1365
+ ) : (
1366
+ <TerminalSquare className="size-3 shrink-0" />
1367
+ )}
1368
+ <button
1369
+ type="button"
1370
+ className="flex min-w-0 flex-1 cursor-pointer items-center gap-1 text-left"
1371
+ onClick={() => onActiveTerminalChange(terminalId)}
1372
+ >
1373
+ <span className="truncate">{terminalLabel}</span>
1374
+ </button>
1375
+ </div>
1376
+ );
1377
+ })}
1378
+ </div>
1379
+ </div>
1380
+ );
1381
+}
1382
+
1383
export default function ThreadTerminalDrawer({
1384
mode = "drawer",
1385
threadRef,
@@ -1360,11 +1451,104 @@ export default function ThreadTerminalDrawer({
1451
} | null>(null);
1452
const didResizeDuringDragRef = useRef(false);
1453
1363
- const { normalizedTerminalIds, resolvedTerminalGroups, terminalLabelById } = useTerminalLayout(
1364
- terminalIds,
1365
- terminalGroups,
1366
- terminalLabelsById,
1367
- );
1454
+ const normalizedTerminalIds = (() => {
1455
+ const normalizedIds: string[] = [];
1456
+ const seen = new Set<string>();
1457
+ for (const id of terminalIds) {
1458
+ const trimmedId = id.trim();
1459
+ if (trimmedId.length === 0 || seen.has(trimmedId)) continue;
1460
+ seen.add(trimmedId);
1461
+ normalizedIds.push(trimmedId);
1462
+ }
1463
+ return normalizedIds;
1464
+ })();
1465
+ const resolvedTerminalGroups = (() => {
1466
+ if (normalizedTerminalIds.length === 0) {
1467
+ return [];
1468
+ }
1469
+ const validTerminalIdSet = new Set(normalizedTerminalIds);
1470
+ const assignedTerminalIds = new Set<string>();
1471
+ const usedGroupIds = new Set<string>();
1472
+ const nextGroups: ThreadTerminalGroup[] = [];
1473
+
1474
+ const assignUniqueGroupId = (groupId: string): string => {
1475
+ if (!usedGroupIds.has(groupId)) {
1476
+ usedGroupIds.add(groupId);
1477
+ return groupId;
1478
+ }
1479
+ let suffix = 2;
1480
+ while (usedGroupIds.has(`${groupId}-${suffix}`)) {
1481
+ suffix += 1;
1482
+ }
1483
+ const uniqueGroupId = `${groupId}-${suffix}`;
1484
+ usedGroupIds.add(uniqueGroupId);
1485
+ return uniqueGroupId;
1486
+ };
1487
+
1488
+ for (const terminalGroup of terminalGroups) {
1489
+ const nextTerminalIds: string[] = [];
1490
+ const seenGroupTerminalIds = new Set<string>();
1491
+ for (const id of terminalGroup.terminalIds) {
1492
+ const terminalId = id.trim();
1493
+ if (terminalId.length === 0) continue;
1494
+ if (seenGroupTerminalIds.has(terminalId)) continue;
1495
+ seenGroupTerminalIds.add(terminalId);
1496
+ if (!validTerminalIdSet.has(terminalId)) continue;
1497
+ if (assignedTerminalIds.has(terminalId)) continue;
1498
+ nextTerminalIds.push(terminalId);
1499
+ }
1500
+ if (nextTerminalIds.length === 0) continue;
1501
+
1502
+ for (const terminalId of nextTerminalIds) {
1503
+ assignedTerminalIds.add(terminalId);
1504
+ }
1505
+
1506
+ const baseGroupId =
1507
+ terminalGroup.id.trim().length > 0
1508
+ ? terminalGroup.id.trim()
1509
+ : `group-${nextTerminalIds[0] ?? normalizedTerminalIds[0] ?? ""}`;
1510
+ nextGroups.push({
1511
+ id: assignUniqueGroupId(baseGroupId),
1512
+ terminalIds: nextTerminalIds,
1513
+ ...(terminalGroup.splitDirection === "vertical"
1514
+ ? { splitDirection: "vertical" as const }
1515
+ : {}),
1516
+ });
1517
+ }
1518
+
1519
+ for (const terminalId of normalizedTerminalIds) {
1520
+ if (assignedTerminalIds.has(terminalId)) continue;
1521
+ nextGroups.push({
1522
+ id: assignUniqueGroupId(`group-${terminalId}`),
1523
+ terminalIds: [terminalId],
1524
+ });
1525
+ }
1526
+
1527
+ const terminalOrderIndex = new Map(
1528
+ normalizedTerminalIds.map((id, index) => [id, index] as const),
1529
+ );
1530
+ nextGroups.sort((left, right) => {
1531
+ const rank = (ids: readonly string[]) =>
1532
+ Math.min(...ids.map((id) => terminalOrderIndex.get(id) ?? Number.POSITIVE_INFINITY));
1533
+ return rank(left.terminalIds) - rank(right.terminalIds);
1534
+ });
1535
+
1536
+ return nextGroups;
1537
+ })();
1538
+ const groupIndexByTerminalId = (() => {
1539
+ const next = new Map<string, number>();
1540
+ for (const [index, terminalGroup] of resolvedTerminalGroups.entries()) {
1541
+ for (const terminalId of terminalGroup.terminalIds) next.set(terminalId, index);
1542
+ }
1543
+ return next;
1544
+ })();
1545
+ const terminalLabelById = (() => {
1546
+ const next = new Map<string, string>();
1547
+ for (const terminalId of normalizedTerminalIds) {
1548
+ next.set(terminalId, terminalLabelsById?.get(terminalId) ?? getTerminalLabel(terminalId));
1549
+ }
1550
+ return next;
1551
+ })();
1552
1553
const resolvedActiveTerminalId =
1554
normalizedTerminalIds.length === 0
@@ -1373,16 +1557,13 @@ export default function ThreadTerminalDrawer({
1557
? activeTerminalId
1558
: (normalizedTerminalIds[0] ?? "");
1559
1376
- const resolvedActiveGroupIndex = (() => {
1377
- const indexById = resolvedTerminalGroups.findIndex(
1378
- (terminalGroup) => terminalGroup.id === activeTerminalGroupId,
1379
- );
1380
- if (indexById >= 0) return indexById;
1381
- const indexByTerminal = resolvedTerminalGroups.findIndex((terminalGroup) =>
1382
- terminalGroup.terminalIds.includes(resolvedActiveTerminalId),
1383
- );
1384
- return indexByTerminal >= 0 ? indexByTerminal : 0;
1385
- })();
1560
+ const groupIndexById = resolvedTerminalGroups.findIndex(
1561
+ (terminalGroup) => terminalGroup.id === activeTerminalGroupId,
1562
+ );
1563
+ const resolvedActiveGroupIndex =
1564
+ groupIndexById >= 0
1565
+ ? groupIndexById
1566
+ : (groupIndexByTerminalId.get(resolvedActiveTerminalId) ?? 0);
1567
1568
const visibleTerminalIds =
1569
resolvedTerminalGroups[resolvedActiveGroupIndex]?.terminalIds ??
@@ -1651,66 +1832,24 @@ export default function ThreadTerminalDrawer({
1832
>
1833
<div className="min-w-0 flex-1">
1834
{isSplitView ? (
1654
- <div
1655
- className="grid h-full w-full min-w-0 gap-0 overflow-hidden"
1656
- style={
1657
- splitDirection === "vertical"
1658
- ? {
1659
- gridTemplateRows: `repeat(${visibleTerminalIds.length}, minmax(0, 1fr))`,
1660
- }
1661
- : {
1662
- gridTemplateColumns: `repeat(${visibleTerminalIds.length}, minmax(0, 1fr))`,
1663
- }
1664
- }
1665
- >
1666
- {visibleTerminalIds.map((terminalId) => {
1667
- const terminalLaunchLocation = resolveTerminalLaunchLocation(terminalId);
1668
- return (
1669
- <div
1670
- key={terminalId}
1671
- className={`min-h-0 min-w-0 ${
1672
- splitDirection === "vertical"
1673
- ? "border-t first:border-t-0"
1674
- : "border-l first:border-l-0"
1675
- } ${
1676
- terminalId === resolvedActiveTerminalId
1677
- ? "border-border"
1678
- : "border-border/70"
1679
- }`}
1680
- onPointerDown={() => {
1681
- if (terminalId !== resolvedActiveTerminalId) {
1682
- onActiveTerminalChange(terminalId);
1683
- }
1684
- }}
1685
- >
1686
- <div className="h-full">
1687
- <TerminalViewport
1688
- advancedTypography={advancedTypography}
1689
- threadRef={threadRef}
1690
- threadId={threadId}
1691
- terminalId={terminalId}
1692
- terminalLabel={terminalLabelById.get(terminalId) ?? "Terminal"}
1693
- cwd={terminalLaunchLocation.cwd}
1694
- {...(terminalLaunchLocation.worktreePath !== undefined
1695
- ? { worktreePath: terminalLaunchLocation.worktreePath }
1696
- : {})}
1697
- {...(terminalLaunchLocation.runtimeEnv
1698
- ? { runtimeEnv: terminalLaunchLocation.runtimeEnv }
1699
- : {})}
1700
- onSessionExited={() => onCloseTerminal(terminalId)}
1701
- onAddTerminalContext={onAddTerminalContext}
1702
- focusRequestId={focusRequestId}
1703
- autoFocus={terminalId === resolvedActiveTerminalId}
1704
- visible={visible}
1705
- resizeEpoch={resizeEpoch}
1706
- drawerHeight={drawerHeight}
1707
- keybindings={keybindings}
1708
- />
1709
- </div>
1710
- </div>
1711
- );
1712
- })}
1713
- </div>
1835
+ <TerminalSplitPanes
1836
+ terminalIds={visibleTerminalIds}
1837
+ splitDirection={splitDirection}
1838
+ activeTerminalId={resolvedActiveTerminalId}
1839
+ terminalLabelById={terminalLabelById}
1840
+ resolveLaunchLocation={resolveTerminalLaunchLocation}
1841
+ onActiveTerminalChange={onActiveTerminalChange}
1842
+ onCloseTerminal={onCloseTerminal}
1843
+ advancedTypography={advancedTypography}
1844
+ threadRef={threadRef}
1845
+ threadId={threadId}
1846
+ onAddTerminalContext={onAddTerminalContext}
1847
+ focusRequestId={focusRequestId}
1848
+ visible={visible}
1849
+ resizeEpoch={resizeEpoch}
1850
+ drawerHeight={drawerHeight}
1851
+ keybindings={keybindings}
1852
+ />
1853
) : (
1854
<div className="h-full">
1855
<TerminalViewport
@@ -1788,87 +1927,19 @@ export default function ThreadTerminalDrawer({
1927
</div>
1928
1929
<div className="min-h-0 flex-1 overflow-y-auto px-1 py-1">
1791
- {resolvedTerminalGroups.map((terminalGroup) => {
1792
- const isGroupActive =
1793
- terminalGroup.terminalIds.includes(resolvedActiveTerminalId);
1794
- const groupActiveTerminalId = isGroupActive
1795
- ? resolvedActiveTerminalId
1796
- : (terminalGroup.terminalIds[0] ?? resolvedActiveTerminalId);
1797
- const terminalCount = terminalGroup.terminalIds.length;
1798
- const isSplitGroup = terminalCount > 1;
1799
- const groupLabel = !isSplitGroup
1800
- ? "Single"
1801
- : terminalGroup.splitDirection === "vertical"
1802
- ? "Stacked"
1803
- : "Side by side";
1804
- const GroupIcon = !isSplitGroup
1805
- ? Square
1806
- : terminalGroup.splitDirection === "vertical"
1807
- ? SquareSplitVertical
1808
- : SquareSplitHorizontal;
1809
-
1810
- return (
1811
- <div key={terminalGroup.id} className="pb-0.5">
1812
- {showGroupHeaders && (
1813
- <button
1814
- type="button"
1815
- className={`flex h-[22px] w-full cursor-pointer items-center gap-1 rounded px-1.5 text-2xs ${
1816
- isGroupActive
1817
- ? "bg-accent/50 text-foreground"
1818
- : "text-muted-foreground hover:bg-accent/40 hover:text-foreground"
1819
- }`}
1820
- onClick={() => onActiveTerminalChange(groupActiveTerminalId)}
1821
- >
1822
- <GroupIcon className="size-3 shrink-0" />
1823
- <span className="min-w-0 flex-1 truncate text-left">{groupLabel}</span>
1824
- <span className="text-muted-foreground/70 text-3xs tabular-nums">
1825
- {terminalCount}
1826
- </span>
1827
- </button>
1828
- )}
1829
-
1830
- <div className="flex flex-col gap-0.5">
1831
- {terminalGroup.terminalIds.map((terminalId) => {
1832
- const isActive = terminalId === resolvedActiveTerminalId;
1833
- const terminalLabel = terminalLabelById.get(terminalId) ?? "Terminal";
1834
- const closeTerminalLabel = `Close ${terminalLabel}${
1835
- isActive && closeShortcutLabel ? ` (${closeShortcutLabel})` : ""
1836
- }`;
1837
- return (
1838
- <div
1839
- key={terminalId}
1840
- className={cn(
1841
- "group/tab flex h-6 w-full items-center gap-0.5 rounded-md pr-2 pl-1.5 text-xs",
1842
- isActive
1843
- ? "bg-accent text-foreground"
1844
- : "text-muted-foreground hover:bg-accent/60 hover:text-foreground",
1845
- )}
1846
- >
1847
- {canOperateTerminal ? (
1848
- <PanelTabCloseButton
1849
- label={closeTerminalLabel}
1850
- onClick={() => confirmCloseTerminal(terminalId)}
1851
- tooltip={closeTerminalLabel}
1852
- >
1853
- <TerminalSquare className="size-3 shrink-0" />
1854
- </PanelTabCloseButton>
1855
- ) : (
1856
- <TerminalSquare className="size-3 shrink-0" />
1857
- )}
1858
- <button
1859
- type="button"
1860
- className="flex min-w-0 flex-1 cursor-pointer items-center gap-1 text-left"
1861
- onClick={() => onActiveTerminalChange(terminalId)}
1862
- >
1863
- <span className="truncate">{terminalLabel}</span>
1864
- </button>
1865
- </div>
1866
- );
1867
- })}
1868
- </div>
1869
- </div>
1870
- );
1871
- })}
1930
+ {resolvedTerminalGroups.map((terminalGroup) => (
1931
+ <TerminalSidebarGroup
1932
+ key={terminalGroup.id}
1933
+ terminalGroup={terminalGroup}
1934
+ activeTerminalId={resolvedActiveTerminalId}
1935
+ showHeader={showGroupHeaders}
1936
+ terminalLabelById={terminalLabelById}
1937
+ closeShortcutLabel={closeShortcutLabel}
1938
+ canOperateTerminal={canOperateTerminal}
1939
+ onActiveTerminalChange={onActiveTerminalChange}
1940
+ onCloseTerminal={confirmCloseTerminal}
1941
+ />
1942
+ ))}
1943
</div>
1944
</aside>
1945
)}