@@ -21,7 +21,7 @@ class Renderer extends EventEmitter<RendererEvents> {
21
21
private progressWrapper : HTMLElement
22
22
private cursor : HTMLElement
23
23
private timeouts : Array < { timeout ?: ReturnType < typeof setTimeout > } > = [ ]
24
- private isScrolling = false
24
+ private isScrollable = false
25
25
private audioData : AudioBuffer | null = null
26
26
private resizeObserver : ResizeObserver | null = null
27
27
private isDragging = false
@@ -526,7 +526,6 @@ class Renderer extends EventEmitter<RendererEvents> {
526
526
// Clear the canvases
527
527
this . canvasWrapper . innerHTML = ''
528
528
this . progressWrapper . innerHTML = ''
529
- this . wrapper . style . width = ''
530
529
531
530
// Width
532
531
if ( this . options . width != null ) {
@@ -540,16 +539,16 @@ class Renderer extends EventEmitter<RendererEvents> {
540
539
const scrollWidth = Math . ceil ( audioData . duration * ( this . options . minPxPerSec || 0 ) )
541
540
542
541
// Whether the container should scroll
543
- this . isScrolling = scrollWidth > parentWidth
544
- const useParentWidth = this . options . fillParent && ! this . isScrolling
542
+ this . isScrollable = scrollWidth > parentWidth
543
+ const useParentWidth = this . options . fillParent && ! this . isScrollable
545
544
// Width of the waveform in pixels
546
545
const width = ( useParentWidth ? parentWidth : scrollWidth ) * pixelRatio
547
546
548
547
// Set the width of the wrapper
549
548
this . wrapper . style . width = useParentWidth ? '100%' : `${ scrollWidth } px`
550
549
551
550
// Set additional styles
552
- this . scrollContainer . style . overflowX = this . isScrolling ? 'auto' : 'hidden'
551
+ this . scrollContainer . style . overflowX = this . isScrollable ? 'auto' : 'hidden'
553
552
this . scrollContainer . classList . toggle ( 'noScrollbar' , ! ! this . options . hideScrollbar )
554
553
this . cursor . style . backgroundColor = `${ this . options . cursorColor || this . options . progressColor } `
555
554
this . cursor . style . width = `${ this . options . cursorWidth } px`
@@ -578,14 +577,17 @@ class Renderer extends EventEmitter<RendererEvents> {
578
577
if ( ! this . audioData ) return
579
578
580
579
// Remember the current cursor position
580
+ const { scrollWidth } = this . scrollContainer
581
581
const oldCursorPosition = this . progressWrapper . clientWidth
582
582
583
- // Set the new zoom level and re -render the waveform
583
+ // Re -render the waveform
584
584
this . render ( this . audioData )
585
585
586
586
// Adjust the scroll position so that the cursor stays in the same place
587
- const newCursortPosition = this . progressWrapper . clientWidth
588
- this . scrollContainer . scrollLeft += newCursortPosition - oldCursorPosition
587
+ if ( this . isScrollable && scrollWidth !== this . scrollContainer . scrollWidth ) {
588
+ const newCursorPosition = this . progressWrapper . clientWidth
589
+ this . scrollContainer . scrollLeft += newCursorPosition - oldCursorPosition
590
+ }
589
591
}
590
592
591
593
zoom ( minPxPerSec : number ) {
@@ -638,7 +640,7 @@ class Renderer extends EventEmitter<RendererEvents> {
638
640
this . cursor . style . left = `${ percents } %`
639
641
this . cursor . style . marginLeft = Math . round ( percents ) === 100 ? `-${ this . options . cursorWidth } px` : ''
640
642
641
- if ( this . isScrolling && this . options . autoScroll ) {
643
+ if ( this . isScrollable && this . options . autoScroll ) {
642
644
this . scrollIntoView ( progress , isPlaying )
643
645
}
644
646
}
0 commit comments