Skip to content

Commit 8859c55

Browse files
committed
fix: input history for characters outside BMP not displaying correctly
closes monkeytypegame#5975
1 parent ab729e6 commit 8859c55

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

frontend/src/ts/test/test-ui.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,13 +1165,17 @@ async function loadWordsHistory(): Promise<boolean> {
11651165
}" input="${input.replace(/"/g, "&quot;").replace(/ /g, "_")}">`;
11661166
}
11671167

1168+
const inputCharacters = Strings.splitIntoCharacters(input);
1169+
const wordCharacters = Strings.splitIntoCharacters(word);
1170+
const correctedCharacters = Strings.splitIntoCharacters(corrected ?? "");
1171+
11681172
let loop;
11691173
if (Config.mode === "zen" || input.length > word.length) {
11701174
//input is longer - extra characters possible (loop over input)
1171-
loop = input.length;
1175+
loop = inputCharacters.length;
11721176
} else {
11731177
//input is shorter or equal (loop over word list)
1174-
loop = word.length;
1178+
loop = wordCharacters.length;
11751179
}
11761180

11771181
if (corrected === undefined) throw new Error("empty corrected word");
@@ -1180,7 +1184,7 @@ async function loadWordsHistory(): Promise<boolean> {
11801184
let correctedChar;
11811185
try {
11821186
correctedChar = !containsKorean
1183-
? corrected[c]
1187+
? correctedCharacters[c]
11841188
: Hangul.assemble(corrected.split(""))[c];
11851189
} catch (e) {
11861190
correctedChar = undefined;
@@ -1196,33 +1200,42 @@ async function loadWordsHistory(): Promise<boolean> {
11961200
) {
11971201
extraCorrected = "extraCorrected";
11981202
}
1199-
if (Config.mode === "zen" || word[c] !== undefined) {
1200-
if (Config.mode === "zen" || input[c] === word[c]) {
1201-
if (correctedChar === input[c] || correctedChar === undefined) {
1202-
wordEl += `<letter class="correct ${extraCorrected}">${input[c]}</letter>`;
1203+
if (Config.mode === "zen" || wordCharacters[c] !== undefined) {
1204+
if (
1205+
Config.mode === "zen" ||
1206+
inputCharacters[c] === wordCharacters[c]
1207+
) {
1208+
if (
1209+
correctedChar === inputCharacters[c] ||
1210+
correctedChar === undefined
1211+
) {
1212+
wordEl += `<letter class="correct ${extraCorrected}">${inputCharacters[c]}</letter>`;
12031213
} else {
12041214
wordEl +=
12051215
`<letter class="corrected ${extraCorrected}">` +
1206-
input[c] +
1216+
inputCharacters[c] +
12071217
"</letter>";
12081218
}
12091219
} else {
1210-
if (input[c] === TestInput.input.current) {
1220+
if (inputCharacters[c] === TestInput.input.current) {
12111221
wordEl +=
12121222
`<letter class='correct ${extraCorrected}'>` +
1213-
word[c] +
1223+
wordCharacters[c] +
12141224
"</letter>";
1215-
} else if (input[c] === undefined) {
1216-
wordEl += "<letter>" + word[c] + "</letter>";
1225+
} else if (inputCharacters[c] === undefined) {
1226+
wordEl += "<letter>" + wordCharacters[c] + "</letter>";
12171227
} else {
12181228
wordEl +=
12191229
`<letter class="incorrect ${extraCorrected}">` +
1220-
word[c] +
1230+
wordCharacters[c] +
12211231
"</letter>";
12221232
}
12231233
}
12241234
} else {
1225-
wordEl += '<letter class="incorrect extra">' + input[c] + "</letter>";
1235+
wordEl +=
1236+
'<letter class="incorrect extra">' +
1237+
inputCharacters[c] +
1238+
"</letter>";
12261239
}
12271240
}
12281241
wordEl += "</div>";

0 commit comments

Comments
 (0)