diff --git a/frontend/src/ts/test/test-input.ts b/frontend/src/ts/test/test-input.ts index 8b18f17efd61..1dfa8cf72d82 100644 --- a/frontend/src/ts/test/test-input.ts +++ b/frontend/src/ts/test/test-input.ts @@ -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; @@ -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, @@ -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"); } @@ -551,4 +554,6 @@ export function restart(): void { correct: 0, incorrect: 0, }; + + resetKeypressTimings(false); } diff --git a/frontend/src/ts/test/test-logic.ts b/frontend/src/ts/test/test-logic.ts index b6cf0c77ca66..22eaf83e5f20 100644 --- a/frontend/src/ts/test/test-logic.ts +++ b/frontend/src/ts/test/test-logic.ts @@ -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(); diff --git a/frontend/src/ts/test/test-stats.ts b/frontend/src/ts/test/test-stats.ts index 16078cf172c1..09b1822c59b5 100644 --- a/frontend/src/ts/test/test-stats.ts +++ b/frontend/src/ts/test/test-stats.ts @@ -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; }