Skip to content

Commit 605c8d7

Browse files
committed
feat: allow non-ascii punctuation characters
fixes #237
1 parent d688f4a commit 605c8d7

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

packages/keybr-textinput/lib/textinput.test.ts

+25-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { toCodePoints } from "@keybr/unicode";
12
import test from "ava";
23
import { TextInput } from "./textinput.ts";
34
import { Attr, type Char, Feedback, type Step } from "./types.ts";
@@ -638,20 +639,30 @@ test("space skips words in the middle of a word, remove garbage", (t) => {
638639
});
639640

640641
test("normalize characters", (t) => {
641-
const textInput = new TextInput("«a»", {
642-
stopOnError: true,
643-
forgiveErrors: false,
644-
spaceSkipsWords: false,
645-
});
646-
647-
t.is(textInput.appendChar(/* " */ 0x0022, 100), Feedback.Succeeded);
648-
t.is(textInput.appendChar(A, 200), Feedback.Succeeded);
649-
t.is(textInput.appendChar(/* " */ 0x0022, 300), Feedback.Succeeded);
650-
t.is(stepsString(textInput.steps), '",100|a,200|",300');
651-
t.is(charsString(textInput.chars), "«|a|»");
652-
t.is(textInput.length, 3);
653-
t.is(textInput.pos, 3);
654-
t.true(textInput.completed);
642+
const check = (text: string, input: string) => {
643+
const textInput = new TextInput(text, {
644+
stopOnError: true,
645+
forgiveErrors: false,
646+
spaceSkipsWords: false,
647+
});
648+
t.is(textInput.text, text);
649+
let timeStamp = 0;
650+
for (const codePoint of toCodePoints(input)) {
651+
t.is(
652+
textInput.appendChar(codePoint, (timeStamp += 100)),
653+
Feedback.Succeeded,
654+
);
655+
}
656+
};
657+
658+
check(`‘’`, `''`);
659+
check(`‘’`, `‘’`);
660+
check(`“”`, `""`);
661+
check(`“”`, `“”`);
662+
check(`«»`, `""`);
663+
check(`«»`, `«»`);
664+
check(`¿?¡!`, `??!!`);
665+
check(`¿?¡!`, `¿?¡!`);
655666
});
656667

657668
test("whitespace", (t) => {

packages/keybr-textinput/lib/textinput.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ export class TextInput {
152152
throw new Error();
153153
}
154154

155-
if (this.at(this.pos).codePoint !== 0x0020 && codePoint === 0x0020) {
155+
const { codePoint: expected } = this.at(this.pos);
156+
157+
if (expected !== 0x0020 && codePoint === 0x0020) {
156158
if (
157159
this.spaceSkipsWords &&
158160
((this.pos > 0 && this.at(this.pos - 1).codePoint !== 0x0020) ||
@@ -167,7 +169,8 @@ export class TextInput {
167169
}
168170

169171
if (
170-
filterText.normalize(this.at(this.pos).codePoint) === codePoint &&
172+
(expected === codePoint ||
173+
filterText.normalize(expected) === codePoint) &&
171174
(this.forgiveErrors || this.#garbage.length === 0)
172175
) {
173176
const typo = this.#typo;

0 commit comments

Comments
 (0)