Skip to content

Commit 214760d

Browse files
committed
impr(dutch): automatically insert 'ij' if the user types the combined ij character
1 parent f29999c commit 214760d

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

frontend/src/ts/input/handlers/insert-text.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
checkIfFailedDueToMinBurst,
1212
checkIfFinished,
1313
} from "../helpers/fail-or-finish";
14-
import { areCharactersVisuallyEqual, isSpace } from "../../utils/strings";
14+
import {
15+
areCharactersVisuallyEqual,
16+
isSpace,
17+
removeLanguageSize,
18+
} from "../../utils/strings";
1519
import * as TestState from "../../test/test-state";
1620
import * as TestLogic from "../../test/test-logic";
1721
import {
@@ -44,6 +48,10 @@ const charOverrides = new Map<string, string>([
4448
// ["æ", "ae"],
4549
]);
4650

51+
const languageCharOverrides = new Map<string, [string, string][]>([
52+
["dutch", [["ij", "ij"]]],
53+
]);
54+
4755
type OnInsertTextParams = {
4856
// might need later?
4957
// inputType: SupportedInputType;
@@ -95,6 +103,29 @@ export async function onInsertText(options: OnInsertTextParams): Promise<void> {
95103
return;
96104
}
97105

106+
const languageOverrides = languageCharOverrides.get(
107+
removeLanguageSize(Config.language),
108+
);
109+
if (languageOverrides !== undefined) {
110+
for (const [targetChar, overrideChar] of languageOverrides) {
111+
if (
112+
options.data === targetChar &&
113+
TestWords.words.getCurrentText()[getCurrentInput().length] !==
114+
options.data
115+
) {
116+
// replace the data with the override
117+
setInputElementValue(
118+
inputValue.slice(0, -options.data.length) + overrideChar,
119+
);
120+
await onInsertText({
121+
...options,
122+
data: overrideChar,
123+
});
124+
return;
125+
}
126+
}
127+
}
128+
98129
// input and target word
99130
const testInput = getCurrentInput();
100131
const currentWord = TestWords.words.getCurrentText();

0 commit comments

Comments
 (0)