Skip to content

Commit 3d4d689

Browse files
committed
fix(tui): add scroll keybindings to permission prompt, error screen, and sidebar
Add keyboard scroll support to scrollboxes that previously had none: - Permission prompt: up/down/j/k, pageup/down, home/end - Error screen: same scroll keys + button shortcuts (c/r/x/esc) - Sidebar: ctrl+shift+up/down Update keybinds.mdx with sidebar scroll documentation. Fixes anomalyco#10923
1 parent 5c8580a commit 3d4d689

4 files changed

Lines changed: 123 additions & 13 deletions

File tree

‎packages/opencode/src/cli/cmd/tui/app.tsx‎

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { render, useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/solid"
22
import { Clipboard } from "@tui/util/clipboard"
3-
import { TextAttributes } from "@opentui/core"
3+
import { type ScrollBoxRenderable, TextAttributes } from "@opentui/core"
44
import { RouteProvider, useRoute } from "@tui/context/route"
55
import { Switch, Match, createEffect, untrack, ErrorBoundary, createSignal, onMount, batch, Show, on } from "solid-js"
66
import { Installation } from "@/installation"
@@ -703,11 +703,7 @@ function ErrorComponent(props: {
703703
props.onExit()
704704
}
705705

706-
useKeyboard((evt) => {
707-
if (evt.ctrl && evt.name === "c") {
708-
handleExit()
709-
}
710-
})
706+
let scroll: ScrollBoxRenderable | undefined
711707
const [copied, setCopied] = createSignal(false)
712708

713709
const issueURL = new URL("https://github.com/anomalyco/opencode/issues/new?template=bug-report.yml")
@@ -740,6 +736,57 @@ function ErrorComponent(props: {
740736
})
741737
}
742738

739+
useKeyboard((evt) => {
740+
if (evt.ctrl && evt.name === "c") {
741+
handleExit()
742+
}
743+
744+
if (evt.name === "x" || evt.name === "escape") {
745+
evt.preventDefault()
746+
handleExit()
747+
}
748+
749+
if (evt.name === "r") {
750+
evt.preventDefault()
751+
props.reset()
752+
}
753+
754+
if (evt.name === "c") {
755+
evt.preventDefault()
756+
copyIssueURL()
757+
}
758+
759+
if (evt.name === "up" || evt.name === "k") {
760+
evt.preventDefault()
761+
scroll?.scrollBy(-1)
762+
}
763+
764+
if (evt.name === "down" || evt.name === "j") {
765+
evt.preventDefault()
766+
scroll?.scrollBy(1)
767+
}
768+
769+
if (evt.name === "pageup") {
770+
evt.preventDefault()
771+
if (scroll) scroll.scrollBy(-scroll.height / 2)
772+
}
773+
774+
if (evt.name === "pagedown") {
775+
evt.preventDefault()
776+
if (scroll) scroll.scrollBy(scroll.height / 2)
777+
}
778+
779+
if (evt.name === "home") {
780+
evt.preventDefault()
781+
scroll?.scrollTo(0)
782+
}
783+
784+
if (evt.name === "end") {
785+
evt.preventDefault()
786+
if (scroll) scroll.scrollTo(scroll.scrollHeight)
787+
}
788+
})
789+
743790
return (
744791
<box flexDirection="column" gap={1} backgroundColor={colors.bg}>
745792
<box flexDirection="row" gap={1} alignItems="center">
@@ -748,21 +795,21 @@ function ErrorComponent(props: {
748795
</text>
749796
<box onMouseUp={copyIssueURL} backgroundColor={colors.primary} padding={1}>
750797
<text attributes={TextAttributes.BOLD} fg={colors.bg}>
751-
Copy issue URL (exception info pre-filled)
798+
C̲opy issue URL (exception info pre-filled)
752799
</text>
753800
</box>
754801
{copied() && <text fg={colors.muted}>Successfully copied</text>}
755802
</box>
756803
<box flexDirection="row" gap={2} alignItems="center">
757804
<text fg={colors.text}>A fatal error occurred!</text>
758805
<box onMouseUp={props.reset} backgroundColor={colors.primary} padding={1}>
759-
<text fg={colors.bg}>Reset TUI</text>
806+
<text fg={colors.bg}>R̲eset TUI</text>
760807
</box>
761808
<box onMouseUp={handleExit} backgroundColor={colors.primary} padding={1}>
762-
<text fg={colors.bg}>Exit</text>
809+
<text fg={colors.bg}>Ex̲it</text>
763810
</box>
764811
</box>
765-
<scrollbox height={Math.floor(term().height * 0.7)}>
812+
<scrollbox height={Math.floor(term().height * 0.7)} ref={(r: ScrollBoxRenderable) => (scroll = r)}>
766813
<text fg={colors.muted}>{props.error.stack}</text>
767814
</scrollbox>
768815
<text fg={colors.text}>{props.error.message}</text>

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createStore } from "solid-js/store"
22
import { createMemo, For, Match, Show, Switch } from "solid-js"
33
import { Portal, useKeyboard, useRenderer, useTerminalDimensions, type JSX } from "@opentui/solid"
4-
import type { TextareaRenderable } from "@opentui/core"
4+
import type { ScrollBoxRenderable, TextareaRenderable } from "@opentui/core"
55
import { useKeybind } from "../../context/keybind"
66
import { useTheme, selectedForeground } from "../../context/theme"
77
import type { PermissionRequest } from "@opencode-ai/sdk/v2"
@@ -69,7 +69,7 @@ function EditBody(props: { request: PermissionRequest }) {
6969
<text fg={theme.textMuted}>Edit {normalizePath(filepath())}</text>
7070
</box>
7171
<Show when={diff()}>
72-
<scrollbox height="100%">
72+
<scrollbox height="100%" ref={(r: ScrollBoxRenderable) => (sharedScrollRef = r)}>
7373
<diff
7474
diff={diff()}
7575
view={view()}
@@ -370,6 +370,9 @@ function RejectPrompt(props: { onConfirm: (message: string) => void; onCancel: (
370370
)
371371
}
372372

373+
// Shared scroll ref that EditBody can set and Prompt can use
374+
let sharedScrollRef: ScrollBoxRenderable | undefined
375+
373376
function Prompt<const T extends Record<string, string>>(props: {
374377
title: string
375378
body: JSX.Element
@@ -407,6 +410,36 @@ function Prompt<const T extends Record<string, string>>(props: {
407410
setStore("selected", next)
408411
}
409412

413+
if (evt.name === "up" || evt.name === "k") {
414+
evt.preventDefault()
415+
sharedScrollRef?.scrollBy(-1)
416+
}
417+
418+
if (evt.name === "down" || evt.name === "j") {
419+
evt.preventDefault()
420+
sharedScrollRef?.scrollBy(1)
421+
}
422+
423+
if (evt.name === "pageup") {
424+
evt.preventDefault()
425+
if (sharedScrollRef) sharedScrollRef.scrollBy(-sharedScrollRef.height / 2)
426+
}
427+
428+
if (evt.name === "pagedown") {
429+
evt.preventDefault()
430+
if (sharedScrollRef) sharedScrollRef.scrollBy(sharedScrollRef.height / 2)
431+
}
432+
433+
if (evt.name === "home") {
434+
evt.preventDefault()
435+
sharedScrollRef?.scrollTo(0)
436+
}
437+
438+
if (evt.name === "end") {
439+
evt.preventDefault()
440+
if (sharedScrollRef) sharedScrollRef.scrollTo(sharedScrollRef.scrollHeight)
441+
}
442+
410443
if (evt.name === "return") {
411444
evt.preventDefault()
412445
props.onSelect(store.selected)
@@ -489,6 +522,11 @@ function Prompt<const T extends Record<string, string>>(props: {
489522
{"ctrl+f"} <span style={{ fg: theme.textMuted }}>{hint()}</span>
490523
</text>
491524
</Show>
525+
<Show when={sharedScrollRef}>
526+
<text fg={theme.text}>
527+
{"↑↓"} <span style={{ fg: theme.textMuted }}>scroll</span>
528+
</text>
529+
</Show>
492530
<text fg={theme.text}>
493531
{"⇆"} <span style={{ fg: theme.textMuted }}>select</span>
494532
</text>

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { useSync } from "@tui/context/sync"
22
import { createMemo, For, Show, Switch, Match } from "solid-js"
33
import { createStore } from "solid-js/store"
4+
import { useKeyboard } from "@opentui/solid"
5+
import type { ScrollBoxRenderable } from "@opentui/core"
46
import { useTheme } from "../../context/theme"
57
import { Locale } from "@/util/locale"
68
import path from "path"
@@ -19,6 +21,18 @@ export function Sidebar(props: { sessionID: string; overlay?: boolean }) {
1921
const diff = createMemo(() => sync.data.session_diff[props.sessionID] ?? [])
2022
const todo = createMemo(() => sync.data.todo[props.sessionID] ?? [])
2123
const messages = createMemo(() => sync.data.message[props.sessionID] ?? [])
24+
let scroll: ScrollBoxRenderable | undefined
25+
26+
useKeyboard((evt) => {
27+
if (evt.ctrl && evt.shift && evt.name === "up") {
28+
evt.preventDefault()
29+
scroll?.scrollBy(-1)
30+
}
31+
if (evt.ctrl && evt.shift && evt.name === "down") {
32+
evt.preventDefault()
33+
scroll?.scrollBy(1)
34+
}
35+
})
2236

2337
const [expanded, setExpanded] = createStore({
2438
mcp: true,
@@ -80,7 +94,7 @@ export function Sidebar(props: { sessionID: string; overlay?: boolean }) {
8094
paddingRight={2}
8195
position={props.overlay ? "absolute" : "relative"}
8296
>
83-
<scrollbox flexGrow={1}>
97+
<scrollbox flexGrow={1} ref={(r: ScrollBoxRenderable) => (scroll = r)}>
8498
<box flexShrink={0} gap={1} paddingRight={1}>
8599
<box paddingRight={1}>
86100
<text fg={theme.text}>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ The OpenCode desktop app prompt input supports common Readline/Emacs-style short
151151

152152
---
153153

154+
## Sidebar scroll
155+
156+
The sidebar can be scrolled using keyboard shortcuts.
157+
158+
| Shortcut | Action |
159+
| ----------------- | -------------------- |
160+
| `ctrl+shift+up` | Scroll up one line |
161+
| `ctrl+shift+down` | Scroll down one line |
162+
163+
---
164+
154165
## Shift+Enter
155166

156167
Some terminals don't send modifier keys with Enter by default. You may need to configure your terminal to send `Shift+Enter` as an escape sequence.

0 commit comments

Comments
 (0)