From e3135550d5a5c81c691017257cda78da5d7429fa Mon Sep 17 00:00:00 2001 From: Miodec Date: Tue, 25 Nov 2025 10:23:07 +0100 Subject: [PATCH 1/4] fix: nospace not working --- frontend/src/ts/input/handlers/insert-text.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/ts/input/handlers/insert-text.ts b/frontend/src/ts/input/handlers/insert-text.ts index 0dd3d55ccf2a..b3d2559e24aa 100644 --- a/frontend/src/ts/input/handlers/insert-text.ts +++ b/frontend/src/ts/input/handlers/insert-text.ts @@ -148,7 +148,7 @@ export async function onInsertText(options: OnInsertTextParams): Promise { // word navigation check const noSpaceForce = isFunboxActiveWithProperty("nospace") && - TestInput.input.current.length === TestWords.words.getCurrent().length; + (testInput + data).length === TestWords.words.getCurrent().length; const shouldGoToNextWord = ((charIsSpace || charIsNewline) && !shouldInsertSpace) || noSpaceForce; From 54b9220a2f5530cc4c2e19c62f4a76b6e09d7248 Mon Sep 17 00:00:00 2001 From: Miodec Date: Tue, 25 Nov 2025 10:36:44 +0100 Subject: [PATCH 2/4] fix: arrows funbox not working --- frontend/src/ts/input/handlers/insert-text.ts | 5 ++++- frontend/src/ts/test/funbox/funbox-functions.ts | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/frontend/src/ts/input/handlers/insert-text.ts b/frontend/src/ts/input/handlers/insert-text.ts index b3d2559e24aa..e7690ba09e6a 100644 --- a/frontend/src/ts/input/handlers/insert-text.ts +++ b/frontend/src/ts/input/handlers/insert-text.ts @@ -135,7 +135,10 @@ export async function onInsertText(options: OnInsertTextParams): Promise { // is char correct const funboxCorrect = findSingleActiveFunboxWithFunction( "isCharCorrect" - )?.functions.isCharCorrect(data, currentWord[inputValue.length] ?? ""); + )?.functions.isCharCorrect( + data, + currentWord[(testInput + data).length - 1] ?? "" + ); const correct = funboxCorrect ?? isCharCorrect({ diff --git a/frontend/src/ts/test/funbox/funbox-functions.ts b/frontend/src/ts/test/funbox/funbox-functions.ts index 2b66718afc86..d26512871475 100644 --- a/frontend/src/ts/test/funbox/funbox-functions.ts +++ b/frontend/src/ts/test/funbox/funbox-functions.ts @@ -257,25 +257,34 @@ const list: Partial> = { }, isCharCorrect(char: string, originalChar: string): boolean { if ( - (char === "a" || char === "ArrowLeft" || char === "j") && + (char === "a" || + char === "ArrowLeft" || + char === "j" || + char === "←") && originalChar === "←" ) { return true; } if ( - (char === "s" || char === "ArrowDown" || char === "k") && + (char === "s" || + char === "ArrowDown" || + char === "k" || + char === "↓") && originalChar === "↓" ) { return true; } if ( - (char === "w" || char === "ArrowUp" || char === "i") && + (char === "w" || char === "ArrowUp" || char === "i" || char === "↑") && originalChar === "↑" ) { return true; } if ( - (char === "d" || char === "ArrowRight" || char === "l") && + (char === "d" || + char === "ArrowRight" || + char === "l" || + char === "→") && originalChar === "→" ) { return true; From 43e0bc783f01ec3d64e7663ceaff919953702129 Mon Sep 17 00:00:00 2001 From: Miodec Date: Tue, 25 Nov 2025 10:37:54 +0100 Subject: [PATCH 3/4] refactor: move const inside an if --- frontend/src/ts/input/handlers/insert-text.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/ts/input/handlers/insert-text.ts b/frontend/src/ts/input/handlers/insert-text.ts index e7690ba09e6a..a9265328a9b0 100644 --- a/frontend/src/ts/input/handlers/insert-text.ts +++ b/frontend/src/ts/input/handlers/insert-text.ts @@ -62,12 +62,12 @@ type OnInsertTextParams = { export async function onInsertText(options: OnInsertTextParams): Promise { const { now, lastInMultiIndex, isCompositionEnding } = options; - const { inputValue } = getInputElementValue(); if (options.data.length > 1) { // remove the entire data from the input value // make sure to not call TestInput.input.syncWithInputElement in here // it will be updated later in the body of onInsertText + const { inputValue } = getInputElementValue(); setInputElementValue(inputValue.slice(0, -options.data.length)); for (let i = 0; i < options.data.length; i++) { const char = options.data[i] as string; From 68266101d0ebb779ab5a2c749da4639c4d369227 Mon Sep 17 00:00:00 2001 From: Miodec Date: Tue, 25 Nov 2025 10:53:45 +0100 Subject: [PATCH 4/4] refactor: move data normalization to a function --- frontend/src/ts/input/handlers/insert-text.ts | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/frontend/src/ts/input/handlers/insert-text.ts b/frontend/src/ts/input/handlers/insert-text.ts index a9265328a9b0..953d0938ae46 100644 --- a/frontend/src/ts/input/handlers/insert-text.ts +++ b/frontend/src/ts/input/handlers/insert-text.ts @@ -95,19 +95,17 @@ export async function onInsertText(options: OnInsertTextParams): Promise { return; } + // input and target word + const testInput = TestInput.input.current; + const currentWord = TestWords.words.getCurrent(); + // if the character is visually equal, replace it with the target character // this ensures all future equivalence checks work correctly - let normalizedData: string | null = null; - const targetChar = - TestWords.words.getCurrent()[TestInput.input.current.length]; - if ( - targetChar !== undefined && - areCharactersVisuallyEqual(options.data, targetChar, Config.language) - ) { - replaceInputElementLastValueChar(targetChar); - normalizedData = targetChar; - } - + const normalizedData = normalizeDataAndUpdateInputIfNeeded( + options.data, + testInput, + currentWord + ); const data = normalizedData ?? options.data; // start if needed @@ -118,8 +116,6 @@ export async function onInsertText(options: OnInsertTextParams): Promise { // helper consts const lastInMultiOrSingle = lastInMultiIndex === true || lastInMultiIndex === undefined; - const testInput = TestInput.input.current; - const currentWord = TestWords.words.getCurrent(); const wordIndex = TestState.activeWordIndex; const charIsSpace = isSpace(data); const charIsNewline = data === "\n"; @@ -289,6 +285,23 @@ export async function onInsertText(options: OnInsertTextParams): Promise { } } +function normalizeDataAndUpdateInputIfNeeded( + data: string, + testInput: string, + currentWord: string +): string | null { + let normalizedData: string | null = null; + const targetChar = currentWord[testInput.length]; + if ( + targetChar !== undefined && + areCharactersVisuallyEqual(data, targetChar, Config.language) + ) { + replaceInputElementLastValueChar(targetChar); + normalizedData = targetChar; + } + return normalizedData; +} + export async function emulateInsertText( options: OnInsertTextParams ): Promise {