@@ -203,7 +203,7 @@ ConfigEvent.subscribe((eventKey, eventValue, nosave) => {
203203 if ( eventKey === "burstHeatmap" ) void applyBurstHeatmap ( ) ;
204204} ) ;
205205
206- export let activeWordElementIndex = 0 ;
206+ export let activeWordElementOffset = 0 ;
207207export let resultVisible = false ;
208208export let activeWordTop = 0 ;
209209export let testRestarting = false ;
@@ -216,8 +216,8 @@ export function setResultVisible(val: boolean): void {
216216 resultVisible = val ;
217217}
218218
219- export function setActiveWordElementIndex ( val : number ) : void {
220- activeWordElementIndex = val ;
219+ export function setActiveWordElementOffset ( val : number ) : void {
220+ activeWordElementOffset = val ;
221221}
222222
223223export function setActiveWordTop ( val : number ) : void {
@@ -243,7 +243,7 @@ export function setResultCalculating(val: boolean): void {
243243
244244export function reset ( ) : void {
245245 currentTestLine = 0 ;
246- activeWordElementIndex = 0 ;
246+ activeWordElementOffset = 0 ;
247247}
248248
249249export function focusWords ( ) : void {
@@ -268,7 +268,7 @@ export function updateActiveElement(
268268 active . classList . remove ( "active" ) ;
269269 }
270270 const newActiveWord = document . querySelectorAll ( "#words .word" ) [
271- activeWordElementIndex
271+ TestState . activeWordIndex - activeWordElementOffset
272272 ] as HTMLElement | undefined ;
273273
274274 if ( newActiveWord == undefined ) {
@@ -453,7 +453,7 @@ export async function updateWordsInputPosition(initial = false): Promise<void> {
453453 const el = document . querySelector ( "#wordsInput" ) as HTMLElement ;
454454 const activeWord =
455455 document . querySelectorAll < HTMLElement > ( "#words .word" ) [
456- activeWordElementIndex
456+ TestState . activeWordIndex - activeWordElementOffset
457457 ] ;
458458
459459 if ( ! activeWord ) {
@@ -926,7 +926,7 @@ export async function updateActiveWordLetters(
926926 }
927927
928928 const activeWord = document . querySelectorAll ( "#words .word" ) ?. [
929- activeWordElementIndex
929+ TestState . activeWordIndex - activeWordElementOffset
930930 ] as HTMLElement ;
931931
932932 activeWord . innerHTML = ret ;
@@ -960,14 +960,15 @@ export function scrollTape(): void {
960960 return ;
961961 }
962962
963+ const wordIndex = TestState . activeWordIndex - activeWordElementOffset ;
963964 const wordsWrapperWidth = (
964965 document . querySelector ( "#wordsWrapper" ) as HTMLElement
965966 ) . offsetWidth ;
966967 let fullWordsWidth = 0 ;
967968 const toHide : JQuery [ ] = [ ] ;
968969 let widthToHide = 0 ;
969- if ( activeWordElementIndex > 0 ) {
970- for ( let i = 0 ; i < activeWordElementIndex ; i ++ ) {
970+ if ( wordIndex > 0 ) {
971+ for ( let i = 0 ; i < wordIndex ; i ++ ) {
971972 const word = document . querySelectorAll ( "#words .word" ) [ i ] as HTMLElement ;
972973 fullWordsWidth += $ ( word ) . outerWidth ( true ) ?? 0 ;
973974 const forWordLeft = Math . floor ( word . offsetLeft ) ;
@@ -979,7 +980,7 @@ export function scrollTape(): void {
979980 }
980981 }
981982 if ( toHide . length > 0 ) {
982- activeWordElementIndex - = toHide . length ;
983+ activeWordElementOffset + = toHide . length ;
983984 toHide . forEach ( ( e ) => e . remove ( ) ) ;
984985 fullWordsWidth -= widthToHide ;
985986 const currentMargin = parseInt ( $ ( "#words" ) . css ( "margin-left" ) , 10 ) ;
@@ -990,7 +991,7 @@ export function scrollTape(): void {
990991 if ( Config . tapeMode === "letter" ) {
991992 if ( TestInput . input . current . length > 0 ) {
992993 const words = document . querySelectorAll ( "#words .word" ) ;
993- const letters = words [ activeWordElementIndex ] ?. querySelectorAll ( "letter" ) ;
994+ const letters = words [ wordIndex ] ?. querySelectorAll ( "letter" ) ;
994995 if ( ! letters ) return ;
995996 for ( let i = 0 ; i < TestInput . input . current . length ; i ++ ) {
996997 const letter = letters [ i ] as HTMLElement ;
@@ -1045,9 +1046,10 @@ export function lineJump(currentTop: number): void {
10451046 ) {
10461047 const hideBound = currentTop ;
10471048
1049+ const wordIndex = TestState . activeWordIndex - activeWordElementOffset ;
10481050 const toHide : JQuery [ ] = [ ] ;
10491051 const wordElements = $ ( "#words .word" ) ;
1050- for ( let i = 0 ; i < activeWordElementIndex ; i ++ ) {
1052+ for ( let i = 0 ; i < wordIndex ; i ++ ) {
10511053 const el = $ ( wordElements [ i ] as HTMLElement ) ;
10521054 if ( el . hasClass ( "hidden" ) ) continue ;
10531055 const forWordTop = Math . floor ( ( el [ 0 ] as HTMLElement ) . offsetTop ) ;
@@ -1114,18 +1116,18 @@ export function lineJump(currentTop: number): void {
11141116 currentLinesAnimating = 0 ;
11151117 activeWordTop = (
11161118 document . querySelectorAll ( "#words .word" ) ?. [
1117- activeWordElementIndex
1119+ wordIndex
11181120 ] as HTMLElement
11191121 ) ?. offsetTop ;
11201122
1121- activeWordElementIndex - = toHide . length ;
1123+ activeWordElementOffset + = toHide . length ;
11221124 lineTransition = false ;
11231125 toHide . forEach ( ( el ) => el . remove ( ) ) ;
11241126 $ ( "#words" ) . css ( "marginTop" , "0" ) ;
11251127 } ) ;
11261128 } else {
11271129 toHide . forEach ( ( el ) => el . remove ( ) ) ;
1128- activeWordElementIndex - = toHide . length ;
1130+ activeWordElementOffset + = toHide . length ;
11291131 $ ( "#paceCaret" ) . css ( {
11301132 top :
11311133 ( document . querySelector ( "#paceCaret" ) as HTMLElement ) . offsetTop -
0 commit comments