Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions frontend/src/ts/input/handlers/insert-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,39 @@ export async function onInsertText(options: OnInsertTextParams): Promise<void> {
correctShiftUsed,
});

// handing cases where last char needs to be removed
// this is here and not in beforeInsertText because we want to penalize for incorrect spaces
// like accuracy, keypress errors, and missed words
let removeLastChar = false;
let visualInputOverride: string | undefined;
if (Config.stopOnError === "letter" && !correct) {
if (!Config.blindMode) {
visualInputOverride = testInput + data;
}
removeLastChar = true;
}

if (!isSpace(data) && correctShiftUsed === false) {
removeLastChar = true;
visualInputOverride = undefined;
incrementIncorrectShiftsInARow();
if (getIncorrectShiftsInARow() >= 5) {
showNoticeNotification("Opposite shift mode is on.", {
important: true,
customTitle: "Reminder",
});
}
} else {
resetIncorrectShiftsInARow();
}

// word navigation check
const noSpaceForce =
isFunboxActiveWithProperty("nospace") &&
(testInput + data).length === TestWords.words.getCurrentText().length;
const shouldGoToNextWord =
((charIsSpace || charIsNewline) && !shouldInsertSpace) || noSpaceForce;
!removeLastChar &&
(((charIsSpace || charIsNewline) && !shouldInsertSpace) || noSpaceForce);

// update test input state
if (!charIsSpace || shouldInsertSpace) {
Expand Down Expand Up @@ -182,32 +209,6 @@ export async function onInsertText(options: OnInsertTextParams): Promise<void> {
TestInput.corrected.update(data, correct);
}

// handing cases where last char needs to be removed
// this is here and not in beforeInsertText because we want to penalize for incorrect spaces
// like accuracy, keypress errors, and missed words
let removeLastChar = false;
let visualInputOverride: string | undefined;
if (Config.stopOnError === "letter" && !correct) {
if (!Config.blindMode) {
visualInputOverride = testInput + data;
}
removeLastChar = true;
}

if (!isSpace(data) && correctShiftUsed === false) {
removeLastChar = true;
visualInputOverride = undefined;
incrementIncorrectShiftsInARow();
if (getIncorrectShiftsInARow() >= 5) {
showNoticeNotification("Opposite shift mode is on.", {
important: true,
customTitle: "Reminder",
});
}
} else {
resetIncorrectShiftsInARow();
}

if (removeLastChar) {
replaceInputElementLastValueChar("");
TestInput.input.syncWithInputElement();
Expand Down
Loading