Skip to content

Commit

Permalink
fix: swipe typing duplicate word issue fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
HemendraSinghShekhawat committed Dec 23, 2024
1 parent 0a9928c commit f2a141f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions frontend/src/ts/controllers/input-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1386,9 +1386,18 @@ $("#wordsInput").on("input", (event) => {
}
}
}
if (inputValue !== currTestInput) {

/* this boolean implies that two input are swipe-typed
consecutively without user inserting space in between */
const doesInputHaveSpaceBetween = inputValue.trim().includes(" ");
if (inputValue !== currTestInput && !doesInputHaveSpaceBetween) {
let diffStart = 0;
while (inputValue[diffStart] === currTestInput[diffStart]) {
// here added undefined check too as the first flag will
// be true even if diffStart overflows the length
while (
inputValue[diffStart] === currTestInput[diffStart] &&
inputValue[diffStart] !== undefined
) {
diffStart++;
}

Expand All @@ -1400,6 +1409,11 @@ $("#wordsInput").on("input", (event) => {
// passing realInput to allow for correct Korean character compilation
handleChar(inputValue[i] as string, i - iOffset, realInputValue);
}
} else {
// simulate space if there is space between input i.e the input is swipe-typed
if (inputValue.trim() !== currTestInput) {
void handleSpace();
}
}

setWordsInput(" " + TestInput.input.current);
Expand Down

0 comments on commit f2a141f

Please sign in to comment.