Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 609ab06

Browse files
authored
Add scroll acceleration support to TUI (anomalyco#4289)
1 parent ec3579d commit 609ab06

5 files changed

Lines changed: 61 additions & 5 deletions

File tree

packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ import { useRoute, useRouteData } from "@tui/context/route"
1717
import { useSync } from "@tui/context/sync"
1818
import { SplitBorder } from "@tui/component/border"
1919
import { useTheme } from "@tui/context/theme"
20-
import { BoxRenderable, ScrollBoxRenderable, TextAttributes, addDefaultParsers } from "@opentui/core"
20+
import {
21+
BoxRenderable,
22+
ScrollBoxRenderable,
23+
TextAttributes,
24+
addDefaultParsers,
25+
MacOSScrollAccel,
26+
type ScrollAcceleration,
27+
} from "@opentui/core"
2128
import { Prompt, type PromptRef } from "@tui/component/prompt"
2229
import type { AssistantMessage, Part, ToolPart, UserMessage, TextPart, ReasoningPart } from "@opencode-ai/sdk"
2330
import { useLocal } from "@tui/context/local"
@@ -62,6 +69,16 @@ import { LSP } from "@/lsp/index.ts"
6269

6370
addDefaultParsers(parsers.parsers)
6471

72+
class CustomSpeedScroll implements ScrollAcceleration {
73+
constructor(private speed: number) {}
74+
75+
tick(_now?: number): number {
76+
return this.speed
77+
}
78+
79+
reset(): void {}
80+
}
81+
6582
const context = createContext<{
6683
width: number
6784
conceal: () => boolean
@@ -95,6 +112,17 @@ export function Session() {
95112
const sidebarVisible = createMemo(() => sidebar() === "show" || (sidebar() === "auto" && wide()))
96113
const contentWidth = createMemo(() => dimensions().width - (sidebarVisible() ? 42 : 0) - 4)
97114

115+
const scrollAcceleration = createMemo(() => {
116+
const tui = sync.data.config.tui
117+
if (tui?.scroll_acceleration?.enabled) {
118+
return new MacOSScrollAccel()
119+
}
120+
if (tui?.scroll_speed) {
121+
return new CustomSpeedScroll(tui.scroll_speed)
122+
}
123+
return undefined
124+
})
125+
98126
createEffect(async () => {
99127
await sync.session
100128
.sync(route.sessionID)
@@ -684,6 +712,7 @@ export function Session() {
684712
stickyScroll={true}
685713
stickyStart="bottom"
686714
flexGrow={1}
715+
scrollAcceleration={scrollAcceleration()}
687716
>
688717
<For each={messages()}>
689718
{(message, index) => (

packages/opencode/src/config/config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,13 @@ export namespace Config {
437437
})
438438

439439
export const TUI = z.object({
440-
scroll_speed: z.number().min(1).optional().default(2).describe("TUI scroll speed"),
440+
scroll_speed: z.number().min(1).optional().default(1).describe("TUI scroll speed"),
441+
scroll_acceleration: z
442+
.object({
443+
enabled: z.boolean().describe("Enable scroll acceleration"),
444+
})
445+
.optional()
446+
.describe("Scroll acceleration settings"),
441447
})
442448

443449
export const Layout = z.enum(["auto", "stretch"]).meta({

packages/sdk/js/src/gen/types.gen.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ export type Config = {
301301
* TUI scroll speed
302302
*/
303303
scroll_speed?: number
304+
/**
305+
* Scroll acceleration settings
306+
*/
307+
scroll_acceleration?: {
308+
/**
309+
* Enable scroll acceleration
310+
*/
311+
enabled: boolean
312+
}
304313
}
305314
/**
306315
* Command configuration, see https://opencode.ai/docs/commands

packages/web/src/content/docs/config.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,19 @@ You can configure TUI-specific settings through the `tui` option.
9393
{
9494
"$schema": "https://opencode.ai/config.json",
9595
"tui": {
96-
"scroll_speed": 3
96+
"scroll_speed": 3,
97+
"scroll_acceleration": {
98+
"enabled": true
99+
}
97100
}
98101
}
99102
```
100103

104+
Available options:
105+
106+
- `scroll_acceleration.enabled` - Enable macOS-style scroll acceleration. **Takes precedence over `scroll_speed`.**
107+
- `scroll_speed` - Custom scroll speed multiplier (default: `1`, minimum: `1`). Ignored if `scroll_acceleration.enabled` is `true`.
108+
101109
[Learn more about using the TUI here](/docs/tui).
102110

103111
---

packages/web/src/content/docs/tui.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,15 @@ You can customize TUI behavior through your OpenCode config file.
336336
{
337337
"$schema": "https://opencode.ai/config.json",
338338
"tui": {
339-
"scroll_speed": 3
339+
"scroll_speed": 3,
340+
"scroll_acceleration": {
341+
"enabled": true
342+
}
340343
}
341344
}
342345
```
343346

344347
### Options
345348

346-
- `scroll_speed` - Controls how fast the TUI scrolls when using scroll commands (default: `2`, minimum: `1`)
349+
- `scroll_acceleration` - Enable macOS-style scroll acceleration for smooth, natural scrolling. When enabled, scroll speed increases with rapid scrolling gestures and stays precise for slower movements. **This setting takes precedence over `scroll_speed` and overrides it when enabled.**
350+
- `scroll_speed` - Controls how fast the TUI scrolls when using scroll commands (default: `1`, minimum: `1`). **Note: This is ignored if `scroll_acceleration.enabled` is set to `true`.**

0 commit comments

Comments
 (0)