Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ function AppShell({
activeMenuItemIndex={activeMenuItemIndex}
activeMenuSpec={activeMenuSpec}
activeMenuWidth={activeMenuWidth}
terminalWidth={terminal.width}
theme={activeTheme}
onHoverItem={setActiveMenuItemIndex}
onSelectItem={(entry) => {
Expand Down
15 changes: 9 additions & 6 deletions src/ui/components/chrome/MenuDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function MenuDropdown({
activeMenuItemIndex,
activeMenuSpec,
activeMenuWidth,
terminalWidth,
theme,
onHoverItem,
onSelectItem,
Expand All @@ -48,17 +49,21 @@ export function MenuDropdown({
activeMenuItemIndex: number;
activeMenuSpec: MenuSpec;
activeMenuWidth: number;
terminalWidth: number;
theme: AppTheme;
onHoverItem: (index: number) => void;
onSelectItem: (entry: Extract<MenuEntry, { kind: "item" }>) => void;
}) {
const clampedWidth = Math.min(activeMenuWidth, Math.max(22, terminalWidth - 2));
const clampedLeft = Math.max(1, Math.min(activeMenuSpec.left, terminalWidth - clampedWidth - 1));

return (
<box
style={{
position: "absolute",
top: 1,
left: activeMenuSpec.left,
width: activeMenuWidth,
left: clampedLeft,
width: clampedWidth,
height: activeMenuEntries.length + 2,
zIndex: 40,
border: true,
Expand All @@ -73,9 +78,7 @@ export function MenuDropdown({
key={`${activeMenuId}:separator:${index}`}
style={{ height: 1, paddingLeft: 1, paddingRight: 1 }}
>
<text fg={theme.border}>
{padText("-".repeat(activeMenuWidth - 4), activeMenuWidth - 2)}
</text>
<text fg={theme.border}>{padText("-".repeat(clampedWidth - 4), clampedWidth - 2)}</text>
</box>
) : (
<box
Expand All @@ -90,7 +93,7 @@ export function MenuDropdown({
onMouseOver={() => onHoverItem(index)}
onMouseUp={() => onSelectItem(entry)}
>
{renderMenuLine(entry, activeMenuWidth - 2, theme, activeMenuItemIndex === index)}
{renderMenuLine(entry, clampedWidth - 2, theme, activeMenuItemIndex === index)}
</box>
),
)}
Expand Down
6 changes: 3 additions & 3 deletions src/ui/components/chrome/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ function menuEntryText(entry: Extract<MenuEntry, { kind: "item" }>) {
return `${check}${entry.label}${hint}`;
}

/** Compute a dropdown width that fits its longest entry with a small floor. */
/** Compute a dropdown content width that fits its longest entry with a little breathing room. */
export function menuWidth(entries: MenuEntry[]) {
return Math.max(
18,
...entries.map((entry) => (entry.kind === "separator" ? 6 : menuEntryText(entry).length)),
20,
...entries.map((entry) => (entry.kind === "separator" ? 6 : menuEntryText(entry).length + 2)),
);
}

Expand Down
28 changes: 28 additions & 0 deletions test/ui-components.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ describe("UI components", () => {
activeMenuItemIndex={0}
activeMenuSpec={{ id: "view", left: 2, width: 6, label: "View" }}
activeMenuWidth={24}
terminalWidth={30}
theme={theme}
onHoverItem={() => {}}
onSelectItem={() => {}}
Expand All @@ -613,6 +614,33 @@ describe("UI components", () => {
expect(frame).toContain("m");
});

test("MenuDropdown repositions wide menus to stay inside the terminal", async () => {
const theme = resolveTheme("midnight", null);
const frame = await captureFrame(
<MenuDropdown
activeMenuId="agent"
activeMenuEntries={[
{ kind: "item", label: "Next annotated file", action: () => {} },
{ kind: "item", label: "Previous annotated file", action: () => {} },
]}
activeMenuItemIndex={0}
activeMenuSpec={{ id: "agent", left: 22, width: 7, label: "Agent" }}
activeMenuWidth={30}
terminalWidth={34}
theme={theme}
onHoverItem={() => {}}
onSelectItem={() => {}}
/>,
34,
6,
);

expect(frame).toContain("Next annotated file");
expect(frame).toContain("Previous annotated file");
expect(frame).toContain("┐");
expect(frame).toContain("┘");
});

test("StatusBar renders filter mode affordance", async () => {
const theme = resolveTheme("midnight", null);
const frame = await captureFrame(
Expand Down
Loading