Skip to content

Commit e8bb0b1

Browse files
zerone0xclaude
andcommitted
fix(tui): ensure arrow keys work for question selection
Add guard clause to validate question data before processing keyboard events, and add stopPropagation() to prevent other handlers from interfering with arrow key navigation in QuestionPrompt. Fixes anomalyco#7638 Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent b41fbda commit e8bb0b1

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

  • packages/opencode/src/cli/cmd/tui/routes/session

‎packages/opencode/src/cli/cmd/tui/routes/session/question.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,21 @@ export function QuestionPrompt(props: { request: QuestionRequest }) {
8989
const dialog = useDialog()
9090

9191
useKeyboard((evt) => {
92+
// Guard: ensure we have valid question data
93+
const currentQuestion = question()
94+
if (!currentQuestion && !confirm()) return
95+
9296
// When editing "Other" textarea
9397
if (store.editing && !confirm()) {
9498
if (evt.name === "escape") {
9599
evt.preventDefault()
100+
evt.stopPropagation()
96101
setStore("editing", false)
97102
return
98103
}
99104
if (evt.name === "return") {
100105
evt.preventDefault()
106+
evt.stopPropagation()
101107
const text = textarea?.plainText?.trim() ?? ""
102108
const prev = store.custom[store.tab]
103109

@@ -149,13 +155,15 @@ export function QuestionPrompt(props: { request: QuestionRequest }) {
149155

150156
if (evt.name === "left" || evt.name === "h") {
151157
evt.preventDefault()
158+
evt.stopPropagation()
152159
const next = (store.tab - 1 + tabs()) % tabs()
153160
setStore("tab", next)
154161
setStore("selected", 0)
155162
}
156163

157164
if (evt.name === "right" || evt.name === "l") {
158165
evt.preventDefault()
166+
evt.stopPropagation()
159167
const next = (store.tab + 1) % tabs()
160168
setStore("tab", next)
161169
setStore("selected", 0)
@@ -164,10 +172,12 @@ export function QuestionPrompt(props: { request: QuestionRequest }) {
164172
if (confirm()) {
165173
if (evt.name === "return") {
166174
evt.preventDefault()
175+
evt.stopPropagation()
167176
submit()
168177
}
169178
if (evt.name === "escape" || keybind.match("app_exit", evt)) {
170179
evt.preventDefault()
180+
evt.stopPropagation()
171181
reject()
172182
}
173183
} else {
@@ -176,16 +186,19 @@ export function QuestionPrompt(props: { request: QuestionRequest }) {
176186

177187
if (evt.name === "up" || evt.name === "k") {
178188
evt.preventDefault()
189+
evt.stopPropagation()
179190
setStore("selected", (store.selected - 1 + total) % total)
180191
}
181192

182193
if (evt.name === "down" || evt.name === "j") {
183194
evt.preventDefault()
195+
evt.stopPropagation()
184196
setStore("selected", (store.selected + 1) % total)
185197
}
186198

187199
if (evt.name === "return") {
188200
evt.preventDefault()
201+
evt.stopPropagation()
189202
if (other()) {
190203
if (!multi()) {
191204
setStore("editing", true)
@@ -210,6 +223,7 @@ export function QuestionPrompt(props: { request: QuestionRequest }) {
210223

211224
if (evt.name === "escape" || keybind.match("app_exit", evt)) {
212225
evt.preventDefault()
226+
evt.stopPropagation()
213227
reject()
214228
}
215229
}

0 commit comments

Comments
 (0)