Skip to content

Commit c7d2f3f

Browse files
committed
feat(tui): let the model dialog be maximized
The model picker opens at the xlarge size (116 columns, clamped to the terminal) instead of medium (60), which on its own fixes the truncation in anomalyco#47600. ctrl+o maximizes it to the full terminal, width and height, and back; the action bar shows "Maximize ctrl+o" / "Restore ctrl+o". Closing the dialog resets it, so it never reopens maximized. A maximized list grows to the terminal height instead of half of it: on a 42-row terminal it shows 29 rows instead of 15. The toggle lives on the shared Dialog so other dialogs can opt in. The key is registered as model_dialog_maximize in the keybind config, which is what makes it appear in the action bar and lets users rebind it.
1 parent e857cbc commit c7d2f3f

5 files changed

Lines changed: 40 additions & 3 deletions

File tree

‎packages/tui/src/component/dialog-model.tsx‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createMemo, createSignal } from "solid-js"
1+
import { createMemo, createSignal, onMount } from "solid-js"
22
import { useLocal } from "../context/local"
33
import { map, pipe, flatMap, entries, filter, sortBy, take } from "remeda"
44
import { DialogSelect } from "../ui/dialog-select"
@@ -14,6 +14,11 @@ export function DialogModel(props: { providerID?: string }) {
1414
const sync = useSync()
1515
const dialog = useDialog()
1616
const [query, setQuery] = createSignal("")
17+
const maximizeTitle = createMemo(() => (dialog.maximized ? "Restore" : "Maximize"))
18+
19+
onMount(() => {
20+
dialog.setSize("xlarge")
21+
})
1722

1823
const connected = useConnected()
1924
const providers = createDialogProviderOptions()
@@ -170,6 +175,13 @@ export function DialogModel(props: { providerID?: string }) {
170175
local.model.toggleFavorite(option.value as { providerID: string; modelID: string })
171176
},
172177
},
178+
{
179+
command: "model.dialog.maximize",
180+
title: maximizeTitle(),
181+
onTrigger() {
182+
dialog.toggleMaximize()
183+
},
184+
},
173185
]}
174186
onFilter={setQuery}
175187
flat={true}

‎packages/tui/src/config/keybind.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export const Definitions = {
118118
stash_delete: keybind("ctrl+d", "Delete stash entry"),
119119
model_provider_list: keybind("ctrl+a", "Open provider list from model dialog"),
120120
model_favorite_toggle: keybind("ctrl+f", "Toggle model favorite status"),
121+
model_dialog_maximize: keybind("ctrl+o", "Maximize or restore the model dialog"),
121122
model_list: keybind("<leader>m", "List available models"),
122123
model_cycle_recent: keybind("f2", "Next recently used model"),
123124
model_cycle_recent_reverse: keybind("shift+f2", "Previous recently used model"),
@@ -324,6 +325,7 @@ export const CommandMap = {
324325
stash_delete: "stash.delete",
325326
model_provider_list: "model.dialog.provider",
326327
model_favorite_toggle: "model.dialog.favorite",
328+
model_dialog_maximize: "model.dialog.maximize",
327329
model_list: "model.list",
328330
model_cycle_recent: "model.cycle_recent",
329331
model_cycle_recent_reverse: "model.cycle_recent_reverse",

‎packages/tui/src/ui/dialog-select.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,14 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
210210
})
211211

212212
const dimensions = useTerminalDimensions()
213-
const height = createMemo(() => Math.min(rows(), Math.floor(dimensions().height / 2) - 6))
213+
// A maximized dialog gives the list the full terminal height, less the rows its own title,
214+
// search field, action bar and padding take up.
215+
const height = createMemo(() =>
216+
Math.min(
217+
rows(),
218+
dialog.maximized ? Math.max(1, dimensions().height - 12) : Math.floor(dimensions().height / 2) - 6,
219+
),
220+
)
214221

215222
const selected = createMemo(() => flat()[store.selected])
216223

‎packages/tui/src/ui/dialog.tsx‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ export function Dialog(
1717
const dimensions = useTerminalDimensions()
1818
const { theme } = useTheme()
1919
const renderer = useRenderer()
20+
const dialog = useDialog()
2021

2122
let dismiss = false
2223
const width = () => {
24+
if (dialog.maximized) return dimensions().width - 2
2325
if (props.size === "xlarge") return 116
2426
if (props.size === "large") return 88
2527
return 60
2628
}
29+
const paddingTop = () => {
30+
if (dialog.maximized) return 2
31+
return dimensions().height / 4
32+
}
2733

2834
return (
2935
<box
@@ -42,7 +48,7 @@ export function Dialog(
4248
alignItems="center"
4349
position="absolute"
4450
zIndex={3000}
45-
paddingTop={dimensions().height / 4}
51+
paddingTop={paddingTop()}
4652
left={0}
4753
top={0}
4854
backgroundColor={RGBA.fromInts(0, 0, 0, 150)}
@@ -73,6 +79,7 @@ function init() {
7379
onClose?: () => void
7480
}[],
7581
size: "medium" as "medium" | "large" | "xlarge",
82+
maximized: false as boolean,
7683
})
7784

7885
const renderer = useRenderer()
@@ -142,6 +149,7 @@ function init() {
142149
if (item.onClose) item.onClose()
143150
}
144151
batch(() => {
152+
setStore("maximized", false)
145153
setStore("size", "medium")
146154
setStore("stack", [])
147155
})
@@ -155,6 +163,7 @@ function init() {
155163
for (const item of store.stack) {
156164
if (item.onClose) item.onClose()
157165
}
166+
setStore("maximized", false)
158167
setStore("size", "medium")
159168
setStore("stack", [
160169
{
@@ -172,6 +181,12 @@ function init() {
172181
setSize(size: "medium" | "large" | "xlarge") {
173182
setStore("size", size)
174183
},
184+
toggleMaximize() {
185+
setStore("maximized", (v) => !v)
186+
},
187+
get maximized() {
188+
return store.maximized
189+
},
175190
}
176191
}
177192

‎packages/web/src/content/docs/keybinds.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ OpenCode has a list of keybinds that you can customize through `tui.json`.
5555
"stash_delete": "ctrl+d",
5656
"model_provider_list": "ctrl+a",
5757
"model_favorite_toggle": "ctrl+f",
58+
"model_dialog_maximize": "ctrl+o",
5859
"model_list": "<leader>m",
5960
"model_cycle_recent": "f2",
6061
"model_cycle_recent_reverse": "shift+f2",

0 commit comments

Comments
 (0)