@@ -118,12 +118,14 @@ export class QuadraticScrollAccel implements ScrollAcceleration {
118118 private multiplier : number
119119 private maxRows : number
120120 private tickHistory : Queue < number >
121+ private buffer : number
121122
122123 constructor ( private opts : QuadraticScrollAccelOptions = { } ) {
123124 this . rollingWindowMs = opts . rollingWindowMs ?? 50
124125 this . multiplier = opts . multiplier ?? 0.3
125126 this . maxRows = opts . maxRows ?? Infinity
126127 this . tickHistory = new Queue < number > ( undefined , 100 )
128+ this . buffer = 0
127129 }
128130
129131 /** Calculates the average number of scroll events */
@@ -136,25 +138,25 @@ export class QuadraticScrollAccel implements ScrollAcceleration {
136138 oldestTick = this . tickHistory . peek ( ) ?? now
137139 }
138140
139- return clamp (
140- Math . round ( this . tickHistory . length * this . multiplier ) ,
141- 1 ,
141+ this . buffer += clamp (
142+ this . tickHistory . length * this . multiplier ,
143+ 0 ,
142144 this . maxRows ,
143145 )
146+ const rows = Math . floor ( this . buffer )
147+ this . buffer -= rows
148+ return rows
144149 }
145150
146151 reset ( ) : void {
147152 this . tickHistory . clear ( )
153+ this . buffer = 0
148154 }
149155}
150156
151157export const createChatScrollAcceleration = ( ) : ScrollAcceleration => {
152158 const environment = resolveScrollEnvironment ( )
153159
154- // MacOS handles the scroll acceleration differently
155- const ScrollAccel =
156- process . platform === 'darwin' ? LinearScrollAccel : QuadraticScrollAccel
157-
158160 let environmentTunedOptions : { multiplier ?: number } = { }
159161
160162 if ( ! environment . enabled ) {
@@ -171,5 +173,5 @@ export const createChatScrollAcceleration = (): ScrollAcceleration => {
171173 }
172174 }
173175
174- return new ScrollAccel ( environmentTunedOptions )
176+ return new QuadraticScrollAccel ( environmentTunedOptions )
175177}
0 commit comments