From 8859c557be5044664288bf7977c4f7b0f563f80c Mon Sep 17 00:00:00 2001 From: Miodec Date: Mon, 21 Oct 2024 12:46:42 +0200 Subject: [PATCH] fix: input history for characters outside BMP not displaying correctly closes #5975 --- frontend/src/ts/test/test-ui.ts | 41 ++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/frontend/src/ts/test/test-ui.ts b/frontend/src/ts/test/test-ui.ts index 53b8565cb..9b31bff53 100644 --- a/frontend/src/ts/test/test-ui.ts +++ b/frontend/src/ts/test/test-ui.ts @@ -1165,13 +1165,17 @@ async function loadWordsHistory(): Promise { }" input="${input.replace(/"/g, """).replace(/ /g, "_")}">`; } + const inputCharacters = Strings.splitIntoCharacters(input); + const wordCharacters = Strings.splitIntoCharacters(word); + const correctedCharacters = Strings.splitIntoCharacters(corrected ?? ""); + let loop; if (Config.mode === "zen" || input.length > word.length) { //input is longer - extra characters possible (loop over input) - loop = input.length; + loop = inputCharacters.length; } else { //input is shorter or equal (loop over word list) - loop = word.length; + loop = wordCharacters.length; } if (corrected === undefined) throw new Error("empty corrected word"); @@ -1180,7 +1184,7 @@ async function loadWordsHistory(): Promise { let correctedChar; try { correctedChar = !containsKorean - ? corrected[c] + ? correctedCharacters[c] : Hangul.assemble(corrected.split(""))[c]; } catch (e) { correctedChar = undefined; @@ -1196,33 +1200,42 @@ async function loadWordsHistory(): Promise { ) { extraCorrected = "extraCorrected"; } - if (Config.mode === "zen" || word[c] !== undefined) { - if (Config.mode === "zen" || input[c] === word[c]) { - if (correctedChar === input[c] || correctedChar === undefined) { - wordEl += `${input[c]}`; + if (Config.mode === "zen" || wordCharacters[c] !== undefined) { + if ( + Config.mode === "zen" || + inputCharacters[c] === wordCharacters[c] + ) { + if ( + correctedChar === inputCharacters[c] || + correctedChar === undefined + ) { + wordEl += `${inputCharacters[c]}`; } else { wordEl += `` + - input[c] + + inputCharacters[c] + ""; } } else { - if (input[c] === TestInput.input.current) { + if (inputCharacters[c] === TestInput.input.current) { wordEl += `` + - word[c] + + wordCharacters[c] + ""; - } else if (input[c] === undefined) { - wordEl += "" + word[c] + ""; + } else if (inputCharacters[c] === undefined) { + wordEl += "" + wordCharacters[c] + ""; } else { wordEl += `` + - word[c] + + wordCharacters[c] + ""; } } } else { - wordEl += '' + input[c] + ""; + wordEl += + '' + + inputCharacters[c] + + ""; } } wordEl += "";