Skip to content

Commit 66628e5

Browse files
committed
Adjust terminal splits for side panel layout
1 parent 84bc1fd commit 66628e5

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

apps/web/src/components/ThreadTerminalPanel.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vitest";
33
import {
44
clampTerminalPanelHeight,
55
resolveTerminalPanelMaxHeight,
6+
resolveTerminalSplitViewGridStyle,
67
resolveTerminalSelectionActionPosition,
78
selectPendingTerminalEventEntries,
89
selectTerminalEventEntriesAfterSnapshot,
@@ -47,6 +48,20 @@ describe("clampTerminalPanelHeight", () => {
4748
});
4849
});
4950

51+
describe("resolveTerminalSplitViewGridStyle", () => {
52+
it("uses columns for bottom-docked terminal splits", () => {
53+
expect(resolveTerminalSplitViewGridStyle("bottom", 3)).toEqual({
54+
gridTemplateColumns: "repeat(3, minmax(0, 1fr))",
55+
});
56+
});
57+
58+
it("uses rows for right-docked terminal splits", () => {
59+
expect(resolveTerminalSplitViewGridStyle("side", 3)).toEqual({
60+
gridTemplateRows: "repeat(3, minmax(0, 1fr))",
61+
});
62+
});
63+
});
64+
5065
describe("resolveTerminalSelectionActionPosition", () => {
5166
it("prefers the selection rect over the last pointer position", () => {
5267
expect(

apps/web/src/components/ThreadTerminalPanel.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ export function clampTerminalPanelHeight(
7979
return Math.min(Math.max(Math.round(safeHeight), MIN_DRAWER_HEIGHT), maxHeight);
8080
}
8181

82+
export function resolveTerminalSplitViewGridStyle(
83+
layout: "bottom" | "side",
84+
terminalCount: number,
85+
): {
86+
gridTemplateColumns?: string;
87+
gridTemplateRows?: string;
88+
} {
89+
const template = `repeat(${terminalCount}, minmax(0, 1fr))`;
90+
return layout === "side" ? { gridTemplateRows: template } : { gridTemplateColumns: template };
91+
}
92+
8293
function writeSystemMessage(terminal: Terminal, message: string): void {
8394
terminal.write(`\r\n[terminal] ${message}\r\n`);
8495
}
@@ -1087,6 +1098,10 @@ export default function ThreadTerminalPanel({
10871098
resolvedTerminalGroups.length > 1 ||
10881099
resolvedTerminalGroups.some((terminalGroup) => terminalGroup.terminalIds.length > 1);
10891100
const hasReachedSplitLimit = visibleTerminalIds.length >= MAX_TERMINALS_PER_GROUP;
1101+
const splitViewGridStyle = useMemo(
1102+
() => resolveTerminalSplitViewGridStyle(layout, visibleTerminalIds.length),
1103+
[layout, visibleTerminalIds.length],
1104+
);
10901105
const terminalLabelById = useMemo(
10911106
() =>
10921107
new Map(
@@ -1105,6 +1120,7 @@ export default function ThreadTerminalPanel({
11051120
const closeTerminalActionLabel = closeShortcutLabel
11061121
? `Close Terminal (${closeShortcutLabel})`
11071122
: "Close Terminal";
1123+
const splitTerminalIconClassName = isSideLayout ? "size-3.25 rotate-90" : "size-3.25";
11081124
const onSplitTerminalAction = useCallback(() => {
11091125
if (hasReachedSplitLimit) return;
11101126
onSplitTerminal();
@@ -1252,7 +1268,7 @@ export default function ThreadTerminalPanel({
12521268
onClick={onSplitTerminalAction}
12531269
label={splitTerminalActionLabel}
12541270
>
1255-
<SquareSplitHorizontal className="size-3.25" />
1271+
<SquareSplitHorizontal className={splitTerminalIconClassName} />
12561272
</TerminalActionButton>
12571273
<div className="h-4 w-px bg-border/80" />
12581274
<TerminalActionButton
@@ -1280,14 +1296,14 @@ export default function ThreadTerminalPanel({
12801296
{isSplitView ? (
12811297
<div
12821298
className="grid h-full w-full min-w-0 gap-0 overflow-hidden"
1283-
style={{
1284-
gridTemplateColumns: `repeat(${visibleTerminalIds.length}, minmax(0, 1fr))`,
1285-
}}
1299+
style={splitViewGridStyle}
12861300
>
12871301
{visibleTerminalIds.map((terminalId) => (
12881302
<div
12891303
key={terminalId}
1290-
className={`min-h-0 min-w-0 border-l first:border-l-0 ${
1304+
className={`min-h-0 min-w-0 ${
1305+
isSideLayout ? "border-t first:border-t-0" : "border-l first:border-l-0"
1306+
} ${
12911307
terminalId === resolvedActiveTerminalId ? "border-border" : "border-border/70"
12921308
}`}
12931309
onMouseDown={() => {
@@ -1351,7 +1367,7 @@ export default function ThreadTerminalPanel({
13511367
onClick={onSplitTerminalAction}
13521368
label={splitTerminalActionLabel}
13531369
>
1354-
<SquareSplitHorizontal className="size-3.25" />
1370+
<SquareSplitHorizontal className={splitTerminalIconClassName} />
13551371
</TerminalActionButton>
13561372
<TerminalActionButton
13571373
className="inline-flex h-full items-center border-l border-border/70 px-1 text-foreground/90 transition-colors hover:bg-accent/70"

0 commit comments

Comments
 (0)