diff --git a/src/renderer.ts b/src/renderer.ts index 655f1c8a0..a65e1d2ba 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -625,15 +625,21 @@ class Renderer extends EventEmitter { // Remember the current cursor position const { scrollWidth } = this.scrollContainer - const oldCursorPosition = this.progressWrapper.clientWidth + const { right: before } = this.progressWrapper.getBoundingClientRect() // Re-render the waveform this.render(this.audioData) // Adjust the scroll position so that the cursor stays in the same place if (this.isScrollable && scrollWidth !== this.scrollContainer.scrollWidth) { - const newCursorPosition = this.progressWrapper.clientWidth - this.scrollContainer.scrollLeft += newCursorPosition - oldCursorPosition + const { right: after } = this.progressWrapper.getBoundingClientRect() + let delta = after - before + // to limit compounding floating-point drift + // we need to round to the half px furthest from 0 + delta *= 2 + delta = delta < 0 ? Math.floor(delta) : Math.ceil(delta) + delta /= 2 + this.scrollContainer.scrollLeft += delta } }