mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-05 05:17:51 +08:00
Merge branch 'input-rewrite'
This commit is contained in:
commit
4f13f32d7f
1 changed files with 14 additions and 5 deletions
|
@ -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").val()) {
|
||||
$("#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);
|
||||
|
|
Loading…
Reference in a new issue