@@ -484,7 +484,6 @@ export async function updateWordsInputPosition(initial = false): Promise<void> {
484
484
}
485
485
486
486
function updateTapeModeLine ( ) : void {
487
- if ( currentTestLine === 0 ) return ;
488
487
const wordElements = document . querySelectorAll < HTMLElement > ( "#words .word" ) ;
489
488
const currentTop = wordElements [ activeWordElementIndex ] ?. offsetTop ?? 0 ;
490
489
@@ -968,38 +967,42 @@ export function scrollTape(): void {
968
967
let widthToHide = 0 ;
969
968
let wordsToHideCount = 0 ;
970
969
let leadingNewLine = 0 ;
971
- let lastAfterNewLineElement = undefined ;
972
970
const linesWidths : number [ ] = [ ] ;
973
971
const toHide : HTMLElement [ ] = [ ] ;
974
972
975
973
// remove leading `.newline` and `.afterNewline` elements
976
974
for ( const child of wordsChildrenArr ) {
977
975
if ( child . classList . contains ( "word" ) ) {
978
- if ( lastAfterNewLineElement ) {
979
- widthToHide += parseInt ( lastAfterNewLineElement . style . marginLeft ) ;
980
- }
981
976
break ;
982
977
} else if ( child . classList . contains ( "newline" ) ) {
983
978
toHide . push ( child ) ;
984
979
} else if ( child . classList . contains ( "afterNewline" ) ) {
985
980
toHide . push ( child ) ;
981
+ widthToHide += parseInt ( child . style . marginLeft ) ;
986
982
leadingNewLine = 1 ;
987
- lastAfterNewLineElement = child ;
988
983
}
989
984
}
990
985
// get last element to loop over
991
986
const activeWordIndex = wordsChildrenArr . indexOf ( activeWordEl ) ;
992
987
const newLinesBeforeActiveWord = wordsChildrenArr
993
988
. slice ( 0 , activeWordIndex )
994
989
. filter ( ( child ) => child . classList . contains ( "afterNewline" ) ) . length ;
995
- const lastVisibleAfterNewline = afterNewLineEls [ newLinesBeforeActiveWord ] as
996
- | HTMLElement
997
- | undefined ;
990
+ // the second .afterNewline after active word is visible during line jump
991
+ let lastVisibleAfterNewline = afterNewLineEls [
992
+ newLinesBeforeActiveWord + 1
993
+ ] as HTMLElement | undefined ;
998
994
let lastElementIndex ;
999
995
if ( lastVisibleAfterNewline ) {
1000
996
lastElementIndex = wordsChildrenArr . indexOf ( lastVisibleAfterNewline ) ;
1001
997
} else {
1002
- lastElementIndex = activeWordIndex - 1 ;
998
+ lastVisibleAfterNewline = afterNewLineEls [ newLinesBeforeActiveWord ] as
999
+ | HTMLElement
1000
+ | undefined ;
1001
+ if ( lastVisibleAfterNewline ) {
1002
+ lastElementIndex = wordsChildrenArr . indexOf ( lastVisibleAfterNewline ) ;
1003
+ } else {
1004
+ lastElementIndex = activeWordIndex - 1 ;
1005
+ }
1003
1006
}
1004
1007
1005
1008
const wordRightMargin = parseInt (
@@ -1037,11 +1040,11 @@ export function scrollTape(): void {
1037
1040
toHide . forEach ( ( el ) => el . remove ( ) ) ;
1038
1041
const currentMargin = parseInt ( wordsEl . style . marginLeft ) ;
1039
1042
wordsEl . style . marginLeft = `${ currentMargin + widthToHide } px` ;
1040
- }
1041
- for ( let i = 0 ; i < linesWidths . length ; i ++ ) {
1042
- (
1043
- afterNewLineEls [ i ] as HTMLElement
1044
- ) . style . marginLeft = ` ${ linesWidths [ i ] } px` ;
1043
+ for ( let i = 0 ; i < linesWidths . length ; i ++ ) {
1044
+ const element = afterNewLineEls [ i ] as HTMLElement ;
1045
+ const currentMargin = parseInt ( element . style . marginLeft ) ;
1046
+ element . style . marginLeft = ` ${ currentMargin - widthToHide } px` ;
1047
+ }
1045
1048
}
1046
1049
1047
1050
let currentWordWidth = 0 ;
@@ -1074,8 +1077,21 @@ export function scrollTape(): void {
1074
1077
}
1075
1078
) ;
1076
1079
jqWords . dequeue ( "leftMargin" ) ;
1080
+ linesWidths . forEach ( ( width , index ) => {
1081
+ $ ( afterNewLineEls [ index ] as Element )
1082
+ . stop ( true , false )
1083
+ . animate (
1084
+ {
1085
+ marginLeft : width ,
1086
+ } ,
1087
+ SlowTimer . get ( ) ? 0 : 125
1088
+ ) ;
1089
+ } ) ;
1077
1090
} else {
1078
1091
wordsEl . style . marginLeft = `${ newMargin } px` ;
1092
+ linesWidths . forEach ( ( width , index ) => {
1093
+ ( afterNewLineEls [ index ] as HTMLElement ) . style . marginLeft = `${ width } px` ;
1094
+ } ) ;
1079
1095
}
1080
1096
}
1081
1097
0 commit comments