From f2a141fe65d4d7fdd7180e0d0395ca9fd28765c4 Mon Sep 17 00:00:00 2001 From: HemendraSinghShekhawat Date: Thu, 7 Nov 2024 23:09:12 +0530 Subject: [PATCH] fix: swipe typing duplicate word issue fixed --- .../src/ts/controllers/input-controller.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/frontend/src/ts/controllers/input-controller.ts b/frontend/src/ts/controllers/input-controller.ts index 50a7c8bc4249..c90f37acd780 100644 --- a/frontend/src/ts/controllers/input-controller.ts +++ b/frontend/src/ts/controllers/input-controller.ts @@ -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++; } @@ -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);