From 26ea544e80efd788f67423524f7d22b12b1b7956 Mon Sep 17 00:00:00 2001 From: spike014 Date: Tue, 29 Jul 2025 12:50:14 +0800 Subject: [PATCH] fix(TextInput): update condition to check for forgiving errors in TextInput class --- packages/keybr-textinput/lib/textinput.test.ts | 18 ++++++++++++++++-- packages/keybr-textinput/lib/textinput.ts | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/keybr-textinput/lib/textinput.test.ts b/packages/keybr-textinput/lib/textinput.test.ts index f4a517e9..ee5c42dc 100644 --- a/packages/keybr-textinput/lib/textinput.test.ts +++ b/packages/keybr-textinput/lib/textinput.test.ts @@ -384,17 +384,31 @@ test("space in garbage", () => { spaceSkipsWords: false, }); + equal(textInput.appendChar(200, Space, 100), Feedback.Failed); + equal(showSteps(textInput), ""); + equal(showChars(textInput), "* |[a]|b|c"); + equal(textInput.length, 3); + equal(textInput.pos, 0); + isFalse(textInput.completed); + equal(textInput.appendChar(100, X, 100), Feedback.Failed); equal(textInput.appendChar(200, Space, 100), Feedback.Failed); equal(showSteps(textInput), ""); - equal(showChars(textInput), "*x|* |[a]|b|c"); + equal(showChars(textInput), "* |*x|* |[a]|b|c"); equal(textInput.length, 3); equal(textInput.pos, 0); isFalse(textInput.completed); equal(textInput.clearChar(), Feedback.Succeeded); equal(showSteps(textInput), ""); - equal(showChars(textInput), "*x|[a]|b|c"); + equal(showChars(textInput), "* |*x|[a]|b|c"); + equal(textInput.length, 3); + equal(textInput.pos, 0); + isFalse(textInput.completed); + + equal(textInput.clearChar(), Feedback.Succeeded); + equal(showSteps(textInput), ""); + equal(showChars(textInput), "* |[a]|b|c"); equal(textInput.length, 3); equal(textInput.pos, 0); isFalse(textInput.completed); diff --git a/packages/keybr-textinput/lib/textinput.ts b/packages/keybr-textinput/lib/textinput.ts index 8ba89376..ad63baaa 100644 --- a/packages/keybr-textinput/lib/textinput.ts +++ b/packages/keybr-textinput/lib/textinput.ts @@ -157,7 +157,7 @@ export class TextInput { this.#skipWord(timeStamp); return this.#return(Feedback.Recovered); } - if (this.#garbage.length === 0 && !this.#typo) { + if (this.forgiveErrors && this.#garbage.length === 0 && !this.#typo) { return this.#return(Feedback.Succeeded); } }