From 5d52e41932e1472df7e93b1374a67e25a06b1f0b Mon Sep 17 00:00:00 2001 From: SeerLite Date: Fri, 1 Oct 2021 22:06:03 -0300 Subject: [PATCH] Don't modify input when it's already the wanted value --- src/js/input-controller.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/js/input-controller.js b/src/js/input-controller.js index 29ad470c7..3e4add6c8 100644 --- a/src/js/input-controller.js +++ b/src/js/input-controller.js @@ -28,6 +28,15 @@ import * as WeakSpot from "./weak-spot"; let dontInsertSpace = false; let correctShiftUsed = true; +function setWordsInput(value) { + // Only change #wordsInput if it's not already the wanted value + // Avoids Safari triggering unneeded events, causing issues with + // dead keys. + if (value !== $("#wordsInput")) { + $("#wordsInput").val(value); + } +} + function backspaceToPrevious() { if (!TestLogic.active) return; @@ -385,7 +394,7 @@ function handleChar(char, charIndex) { if (!thisCharCorrect && Misc.trailingComposeChars.test(resultingWord)) { TestLogic.input.current = resultingWord; - $("#wordsInput").val(" " + TestLogic.input.current); + setWordsInput(" " + TestLogic.input.current); TestUI.updateWordElement(); Caret.updatePosition(); return; @@ -458,7 +467,7 @@ function handleChar(char, charIndex) { charIndex < TestLogic.words.getCurrent().length + 20) ) { TestLogic.input.current = resultingWord; - $("#wordsInput").val(" " + TestLogic.input.current); + setWordsInput(" " + TestLogic.input.current); } if (!thisCharCorrect && Config.difficulty == "master") { @@ -539,7 +548,7 @@ function handleChar(char, charIndex) { Caret.updatePosition(); } - $("#wordsInput").val(" " + TestLogic.input.current); + setWordsInput(" " + TestLogic.input.current); } function handleTab(event) { @@ -687,7 +696,7 @@ $(document).keydown((event) => { if (event.key === "Backspace" && TestLogic.input.current.length === 0) { backspaceToPrevious(); if (TestLogic.input.current) - $("#wordsInput").val(" " + TestLogic.input.current + " "); + setWordsInput(" " + TestLogic.input.current + " "); } if (event.key === "Enter") { @@ -785,7 +794,7 @@ $("#wordsInput").on("input", (event) => { } } - event.target.value = " " + TestLogic.input.current; + setWordsInput(" " + TestLogic.input.current); let acc = Misc.roundTo2(TestStats.calculateAccuracy()); LiveAcc.update(acc);