Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Improve scroll position adjustments on zoom in/out #3518

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,15 +625,21 @@ class Renderer extends EventEmitter<RendererEvents> {

// 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
}
}

Expand Down
Loading