mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-20 01:04:22 +01:00
Add scroll acceleration support to TUI (#4289)
This commit is contained in:
@@ -17,7 +17,14 @@ import { useRoute, useRouteData } from "@tui/context/route"
|
|||||||
import { useSync } from "@tui/context/sync"
|
import { useSync } from "@tui/context/sync"
|
||||||
import { SplitBorder } from "@tui/component/border"
|
import { SplitBorder } from "@tui/component/border"
|
||||||
import { useTheme } from "@tui/context/theme"
|
import { useTheme } from "@tui/context/theme"
|
||||||
import { BoxRenderable, ScrollBoxRenderable, TextAttributes, addDefaultParsers } from "@opentui/core"
|
import {
|
||||||
|
BoxRenderable,
|
||||||
|
ScrollBoxRenderable,
|
||||||
|
TextAttributes,
|
||||||
|
addDefaultParsers,
|
||||||
|
MacOSScrollAccel,
|
||||||
|
type ScrollAcceleration,
|
||||||
|
} from "@opentui/core"
|
||||||
import { Prompt, type PromptRef } from "@tui/component/prompt"
|
import { Prompt, type PromptRef } from "@tui/component/prompt"
|
||||||
import type { AssistantMessage, Part, ToolPart, UserMessage, TextPart, ReasoningPart } from "@opencode-ai/sdk"
|
import type { AssistantMessage, Part, ToolPart, UserMessage, TextPart, ReasoningPart } from "@opencode-ai/sdk"
|
||||||
import { useLocal } from "@tui/context/local"
|
import { useLocal } from "@tui/context/local"
|
||||||
@@ -62,6 +69,16 @@ import { LSP } from "@/lsp/index.ts"
|
|||||||
|
|
||||||
addDefaultParsers(parsers.parsers)
|
addDefaultParsers(parsers.parsers)
|
||||||
|
|
||||||
|
class CustomSpeedScroll implements ScrollAcceleration {
|
||||||
|
constructor(private speed: number) {}
|
||||||
|
|
||||||
|
tick(_now?: number): number {
|
||||||
|
return this.speed
|
||||||
|
}
|
||||||
|
|
||||||
|
reset(): void {}
|
||||||
|
}
|
||||||
|
|
||||||
const context = createContext<{
|
const context = createContext<{
|
||||||
width: number
|
width: number
|
||||||
conceal: () => boolean
|
conceal: () => boolean
|
||||||
@@ -95,6 +112,17 @@ export function Session() {
|
|||||||
const sidebarVisible = createMemo(() => sidebar() === "show" || (sidebar() === "auto" && wide()))
|
const sidebarVisible = createMemo(() => sidebar() === "show" || (sidebar() === "auto" && wide()))
|
||||||
const contentWidth = createMemo(() => dimensions().width - (sidebarVisible() ? 42 : 0) - 4)
|
const contentWidth = createMemo(() => dimensions().width - (sidebarVisible() ? 42 : 0) - 4)
|
||||||
|
|
||||||
|
const scrollAcceleration = createMemo(() => {
|
||||||
|
const tui = sync.data.config.tui
|
||||||
|
if (tui?.scroll_acceleration?.enabled) {
|
||||||
|
return new MacOSScrollAccel()
|
||||||
|
}
|
||||||
|
if (tui?.scroll_speed) {
|
||||||
|
return new CustomSpeedScroll(tui.scroll_speed)
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
})
|
||||||
|
|
||||||
createEffect(async () => {
|
createEffect(async () => {
|
||||||
await sync.session
|
await sync.session
|
||||||
.sync(route.sessionID)
|
.sync(route.sessionID)
|
||||||
@@ -684,6 +712,7 @@ export function Session() {
|
|||||||
stickyScroll={true}
|
stickyScroll={true}
|
||||||
stickyStart="bottom"
|
stickyStart="bottom"
|
||||||
flexGrow={1}
|
flexGrow={1}
|
||||||
|
scrollAcceleration={scrollAcceleration()}
|
||||||
>
|
>
|
||||||
<For each={messages()}>
|
<For each={messages()}>
|
||||||
{(message, index) => (
|
{(message, index) => (
|
||||||
|
|||||||
@@ -437,7 +437,13 @@ export namespace Config {
|
|||||||
})
|
})
|
||||||
|
|
||||||
export const TUI = z.object({
|
export const TUI = z.object({
|
||||||
scroll_speed: z.number().min(1).optional().default(2).describe("TUI scroll speed"),
|
scroll_speed: z.number().min(1).optional().default(1).describe("TUI scroll speed"),
|
||||||
|
scroll_acceleration: z
|
||||||
|
.object({
|
||||||
|
enabled: z.boolean().describe("Enable scroll acceleration"),
|
||||||
|
})
|
||||||
|
.optional()
|
||||||
|
.describe("Scroll acceleration settings"),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const Layout = z.enum(["auto", "stretch"]).meta({
|
export const Layout = z.enum(["auto", "stretch"]).meta({
|
||||||
|
|||||||
@@ -301,6 +301,15 @@ export type Config = {
|
|||||||
* TUI scroll speed
|
* TUI scroll speed
|
||||||
*/
|
*/
|
||||||
scroll_speed?: number
|
scroll_speed?: number
|
||||||
|
/**
|
||||||
|
* Scroll acceleration settings
|
||||||
|
*/
|
||||||
|
scroll_acceleration?: {
|
||||||
|
/**
|
||||||
|
* Enable scroll acceleration
|
||||||
|
*/
|
||||||
|
enabled: boolean
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Command configuration, see https://opencode.ai/docs/commands
|
* Command configuration, see https://opencode.ai/docs/commands
|
||||||
|
|||||||
@@ -93,11 +93,19 @@ You can configure TUI-specific settings through the `tui` option.
|
|||||||
{
|
{
|
||||||
"$schema": "https://opencode.ai/config.json",
|
"$schema": "https://opencode.ai/config.json",
|
||||||
"tui": {
|
"tui": {
|
||||||
"scroll_speed": 3
|
"scroll_speed": 3,
|
||||||
|
"scroll_acceleration": {
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Available options:
|
||||||
|
|
||||||
|
- `scroll_acceleration.enabled` - Enable macOS-style scroll acceleration. **Takes precedence over `scroll_speed`.**
|
||||||
|
- `scroll_speed` - Custom scroll speed multiplier (default: `1`, minimum: `1`). Ignored if `scroll_acceleration.enabled` is `true`.
|
||||||
|
|
||||||
[Learn more about using the TUI here](/docs/tui).
|
[Learn more about using the TUI here](/docs/tui).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -336,11 +336,15 @@ You can customize TUI behavior through your OpenCode config file.
|
|||||||
{
|
{
|
||||||
"$schema": "https://opencode.ai/config.json",
|
"$schema": "https://opencode.ai/config.json",
|
||||||
"tui": {
|
"tui": {
|
||||||
"scroll_speed": 3
|
"scroll_speed": 3,
|
||||||
|
"scroll_acceleration": {
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
- `scroll_speed` - Controls how fast the TUI scrolls when using scroll commands (default: `2`, minimum: `1`)
|
- `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.**
|
||||||
|
- `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`.**
|
||||||
|
|||||||
Reference in New Issue
Block a user