Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions frontend/src/ts/test/test-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,10 @@ function updateOverlap(now: number): void {
}
}

export function resetKeypressTimings(): void {
//because keydown triggers before input, we need to grab the first keypress data here and carry it over
function carryoverFirstKeypress(): void {
// Because keydown triggers before input, we need to grab the first keypress data here and carry it over

//take the key with the largest index
// Take the key with the largest index
const lastKey = Object.keys(keyDownData).reduce((a, b) => {
const aIndex = keyDownData[a]?.index;
const bIndex = keyDownData[b]?.index;
Expand All @@ -464,10 +464,30 @@ export function resetKeypressTimings(): void {
return aIndex > bIndex ? a : b;
}, "");

//get the data
// Get the data
const lastKeyData = keyDownData[lastKey];

//reset
// Carry over
if (lastKeyData !== undefined) {
keypressTimings = {
spacing: {
first: lastKeyData.timestamp,
last: lastKeyData.timestamp,
array: [],
},
duration: {
array: [0],
},
};
keyDownData[lastKey] = {
timestamp: lastKeyData.timestamp,
// Make sure to set it to the first index
index: 0,
};
}
}

export function resetKeypressTimings(carryover: boolean): void {
keypressTimings = {
spacing: {
first: -1,
Expand All @@ -485,24 +505,7 @@ export function resetKeypressTimings(): void {
keyDownData = {};
noCodeIndex = 0;

//carry over
if (lastKeyData !== undefined) {
keypressTimings = {
spacing: {
first: lastKeyData.timestamp,
last: lastKeyData.timestamp,
array: [],
},
duration: {
array: [0],
},
};
keyDownData[lastKey] = {
timestamp: lastKeyData.timestamp,
// make sure to set it to the first index
index: 0,
};
}
if (carryover) carryoverFirstKeypress();

console.debug("Keypress timings reset");
}
Expand Down Expand Up @@ -551,4 +554,6 @@ export function restart(): void {
correct: 0,
incorrect: 0,
};

resetKeypressTimings(false);
}
2 changes: 1 addition & 1 deletion frontend/src/ts/test/test-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function startTest(now: number): boolean {
TestState.setActive(true);
Replay.startReplayRecording();
Replay.replayGetWordsList(TestWords.words.list);
TestInput.resetKeypressTimings();
TestInput.resetKeypressTimings(true);
Time.set(0);
TestTimer.clear();

Expand Down
5 changes: 0 additions & 5 deletions frontend/src/ts/test/test-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ export function calculateTestSeconds(now?: number): number {
duration = (now - start) / 1000;
}

if (Config.mode === "zen" && duration < 0) {
duration = 0;
console.log("Zen mode with negative duration detected, setting to 0");
}

return duration;
}

Expand Down
Loading