Skip to content

Commit c63c152

Browse files
committed
switch everything to constant scroll
1 parent 1441a8e commit c63c152

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

cli/src/utils/chat-scroll-accel.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ const ENVIRONMENTS = ['zed', 'ghostty', 'vscode'] as const
1919
type ScrollEnvironmentType = (typeof ENVIRONMENTS)[number] | 'default'
2020

2121
const ENV_MULTIPLIERS = {
22-
zed: 0.015,
23-
ghostty: 0.15,
24-
zed: 0.07,
25-
ghostty: 0.2,
26-
vscode: 0.05,
27-
default: 0.05,
22+
zed: 0.5,
23+
ghostty: 0.5,
24+
vscode: 0.5,
25+
default: 0.5,
2826
} satisfies Record<ScrollEnvironmentType, number>
2927

3028
type ScrollEnvironment = {
@@ -51,24 +49,25 @@ const resolveScrollEnvironment = (): ScrollEnvironment => {
5149
return { type: 'default', multiplier }
5250
}
5351

54-
type LinearScrollAccelOptions = {
52+
type ConstantScrollAccelOptions = {
5553
/** How fast to scale the scrolling. */
5654
multiplier?: number
5755
}
5856

5957
/** Always scrolls at a constant speed per tick. */
60-
export class LinearScrollAccel implements ScrollAcceleration {
58+
export class ConstantScrollAccel implements ScrollAcceleration {
6159
private multiplier: number
6260
private buffer: number
6361

64-
constructor(private opts: LinearScrollAccelOptions = {}) {
62+
constructor(private opts: ConstantScrollAccelOptions = {}) {
6563
this.buffer = 0
6664
this.multiplier = opts.multiplier ?? 1
6765
}
6866

6967
tick(): number {
7068
this.buffer += this.multiplier
71-
const rows = Math.floor(this.buffer)
69+
const rows =
70+
this.buffer > 0 ? Math.floor(this.buffer) : Math.ceil(this.buffer)
7271
this.buffer -= rows
7372
return rows
7473
}
@@ -78,7 +77,7 @@ export class LinearScrollAccel implements ScrollAcceleration {
7877
}
7978
}
8079

81-
type QuadraticScrollAccelOptions = {
80+
type LinearScrollAccelOptions = {
8281
/** How fast to scale the scrolling. */
8382
multiplier?: number
8483

@@ -100,14 +99,14 @@ type QuadraticScrollAccelOptions = {
10099
* The number of lines scrolled is proportional to the number of scroll events
101100
* in the last `rollingWindowMs`.
102101
*/
103-
export class QuadraticScrollAccel implements ScrollAcceleration {
102+
export class LinearScrollAccel implements ScrollAcceleration {
104103
private rollingWindowMs: number
105104
private multiplier: number
106105
private maxRows: number
107106
private tickHistory: Queue<number>
108107
private buffer: number
109108

110-
constructor(private opts: QuadraticScrollAccelOptions = {}) {
109+
constructor(private opts: LinearScrollAccelOptions = {}) {
111110
this.rollingWindowMs = opts.rollingWindowMs ?? 100
112111
this.multiplier = opts.multiplier ?? 0.3
113112
this.maxRows = opts.maxRows ?? Infinity
@@ -127,7 +126,7 @@ export class QuadraticScrollAccel implements ScrollAcceleration {
127126

128127
this.buffer += clamp(
129128
this.tickHistory.length * this.multiplier,
130-
0,
129+
-this.maxRows,
131130
this.maxRows,
132131
)
133132
const rows = Math.floor(this.buffer)
@@ -144,7 +143,7 @@ export class QuadraticScrollAccel implements ScrollAcceleration {
144143
export const createChatScrollAcceleration = (): ScrollAcceleration => {
145144
const environment = resolveScrollEnvironment()
146145

147-
return new QuadraticScrollAccel({
146+
return new ConstantScrollAccel({
148147
multiplier: ENV_MULTIPLIERS[environment.type] * environment.multiplier,
149148
})
150149
}

0 commit comments

Comments
 (0)