From a6f1e62c7c0a3834fa0ab1b184895b62801534de Mon Sep 17 00:00:00 2001 From: SeerLite Date: Wed, 6 Oct 2021 12:05:20 -0300 Subject: [PATCH] Fix layout emulator issues (#1957) by seerlite * Reset #wordsInput when using layout emulator too * Refactor input and fix emulation live acc --- src/js/input-controller.js | 40 ++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/js/input-controller.js b/src/js/input-controller.js index 0f2993400..0594dee47 100644 --- a/src/js/input-controller.js +++ b/src/js/input-controller.js @@ -37,6 +37,21 @@ function setWordsInput(value) { } } +function updateUI() { + let acc = Misc.roundTo2(TestStats.calculateAccuracy()); + LiveAcc.update(acc); + + if (Config.keymapMode === "next" && Config.mode !== "zen") { + Keymap.highlightKey( + TestLogic.words + .getCurrent() + .charAt(TestLogic.input.current.length) + .toString() + .toUpperCase() + ); + } +} + function backspaceToPrevious() { if (!TestLogic.active) return; @@ -718,16 +733,7 @@ $(document).keydown((event) => { if (char !== null) { event.preventDefault(); handleChar(char, TestLogic.input.current.length); - } - - if (Config.keymapMode === "next" && Config.mode !== "zen") { - Keymap.highlightKey( - TestLogic.words - .getCurrent() - .charAt(TestLogic.input.current.length) - .toString() - .toUpperCase() - ); + updateUI(); } } }); @@ -787,19 +793,7 @@ $("#wordsInput").on("input", (event) => { } setWordsInput(" " + TestLogic.input.current); - - let acc = Misc.roundTo2(TestStats.calculateAccuracy()); - LiveAcc.update(acc); - - if (Config.keymapMode === "next" && Config.mode !== "zen") { - Keymap.highlightKey( - TestLogic.words - .getCurrent() - .charAt(TestLogic.input.current.length) - .toString() - .toUpperCase() - ); - } + updateUI(); // force caret at end of input // doing it on next cycle because Chromium on Android won't let me edit