Don't modify input when it's already the wanted value

This commit is contained in:
SeerLite 2021-10-01 22:06:03 -03:00
parent f7d2be17d3
commit 5d52e41932

View file

@ -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);