Skip to content
18 changes: 15 additions & 3 deletions frontend/src/ts/test/test-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,8 @@ function buildWordLettersHTML(
async function loadWordsHistory(): Promise<boolean> {
$("#resultWordsHistory .words").empty();
let wordsHTML = "";
for (let i = 0; i < TestInput.input.getHistory().length + 2; i++) {
const inputHistoryLength = TestInput.input.getHistory().length;
for (let i = 0; i < inputHistoryLength + 2; i++) {
const input = TestInput.input.getHistory(i);
const corrected = TestInput.corrected.getHistory(i);
const word = TestWords.words.get(i);
Expand All @@ -1303,8 +1304,19 @@ async function loadWordsHistory(): Promise<boolean> {
throw new Error("empty input word");
}

const errorClass =
Config.mode === "zen" ? "" : input !== word ? "error" : "";
const isIncorrectWord = input !== word;
const isLastWord = i === inputHistoryLength - 1;
const isTimedTest =
Config.mode === "time" ||
(Config.mode === "custom" && CustomText.getLimitMode() === "time") ||
(Config.mode === "custom" && CustomText.getLimitValue() === 0);
const isPartiallyCorrect = word.substring(0, input.length) === input;

const shouldShowError =
Config.mode !== "zen" &&
!(isLastWord && isTimedTest && isPartiallyCorrect);

const errorClass = isIncorrectWord && shouldShowError ? "error" : "";

if (corrected !== undefined && corrected !== "") {
const correctedChar = !containsKorean
Expand Down