@@ -94,14 +94,14 @@ export function removeCuesInRange(
9494 }
9595}
9696
97- // Find first cue starting after given time.
97+ // Find first cue starting at or after given time.
9898// Modified version of binary search O(log(n)).
99- function getFirstCueIndexAfterTime (
99+ function getFirstCueIndexFromTime (
100100 cues : TextTrackCueList | TextTrackCue [ ] ,
101101 time : number ,
102102) : number {
103- // If first cue starts after time, start there
104- if ( time < cues [ 0 ] . startTime ) {
103+ // If first cue starts at or after time, start there
104+ if ( time <= cues [ 0 ] . startTime ) {
105105 return 0 ;
106106 }
107107 // If the last cue ends before time there is no overlap
@@ -112,9 +112,9 @@ function getFirstCueIndexAfterTime(
112112
113113 let left = 0 ;
114114 let right = len ;
115-
115+ let mid ;
116116 while ( left <= right ) {
117- const mid = Math . floor ( ( right + left ) / 2 ) ;
117+ mid = Math . floor ( ( right + left ) / 2 ) ;
118118
119119 if ( time < cues [ mid ] . startTime ) {
120120 right = mid - 1 ;
@@ -138,7 +138,7 @@ export function getCuesInRange(
138138 end : number ,
139139) : TextTrackCue [ ] {
140140 const cuesFound : TextTrackCue [ ] = [ ] ;
141- const firstCueInRange = getFirstCueIndexAfterTime ( cues , start ) ;
141+ const firstCueInRange = getFirstCueIndexFromTime ( cues , start ) ;
142142 if ( firstCueInRange > - 1 ) {
143143 for ( let i = firstCueInRange , len = cues . length ; i < len ; i ++ ) {
144144 const cue = cues [ i ] ;
0 commit comments