Skip to content

Commit ca0e072

Browse files
committed
time mode now shows 3 lines and generates a new line only when the second is completed
1 parent 49e3de8 commit ca0e072

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

public/js/script.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let testStart, testEnd;
99
let wpmHistory = [];
1010
let currentCommands = commands;
1111
let restartCount = 0;
12+
let currentTestLine = 0;
1213

1314
let accuracyStats = {
1415
correct: 0,
@@ -215,7 +216,7 @@ function showWords() {
215216
$("#words").append(w);
216217
}
217218
$("#words").removeClass('hidden');
218-
const wordHeight = $($(".word")[0]).outerHeight();
219+
const wordHeight = $($(".word")[0]).outerHeight(true);
219220
$("#words").css("height", wordHeight * 3 + 'px').css("overflow", "hidden");
220221
}
221222
updateActiveElement();
@@ -554,7 +555,7 @@ function restartTest() {
554555
hideCaret();
555556
testActive = false;
556557
hideLiveWpm();
557-
558+
currentTestLine = 0;
558559
let el = null;
559560
if($("#words").hasClass('hidden')){
560561
//results are being displayed
@@ -1024,10 +1025,18 @@ $(document).keydown((event) => {
10241025
let nextTop = $($("#words .word")[currentWordIndex + 1]).position().top;
10251026
if (nextTop > currentTop) {
10261027
//last word of the line
1027-
for (let i = 0; i < currentWordIndex + 1; i++) {
1028-
$($("#words .word")[i]).addClass("hidden");
1029-
// addWordLine();
1028+
if(currentTestLine > 0){
1029+
let toHide = [];
1030+
for (let i = 0; i < currentWordIndex + 1; i++) {
1031+
let forWordTop = $($("#words .word")[i]).position().top;
1032+
if(forWordTop < currentTop){
1033+
// $($("#words .word")[i]).addClass("hidden");
1034+
toHide.push($($("#words .word")[i]));
1035+
}
1036+
}
1037+
toHide.forEach(el => el.addClass('hidden'));
10301038
}
1039+
currentTestLine++;
10311040
}
10321041
}
10331042
if (currentWord == currentInput) {

0 commit comments

Comments
 (0)