Skip to content

Commit 2c94bff

Browse files
authored
refactor(funbox): remove isCharCorrect function (@Leonabcd123) (#8156)
`arrows` funbox doesn't need it, no other funbox defines it.
1 parent 3a7a710 commit 2c94bff

4 files changed

Lines changed: 8 additions & 63 deletions

File tree

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

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import {
1818
} from "../../utils/strings";
1919
import * as TestState from "../../test/test-state";
2020
import * as TestLogic from "../../test/test-logic";
21-
import {
22-
findSingleActiveFunboxWithFunction,
23-
isFunboxActiveWithProperty,
24-
} from "../../test/funbox/list";
21+
import { isFunboxActiveWithProperty } from "../../test/funbox/list";
2522
import { Config } from "../../config/store";
2623
import { flash } from "../../events/keymap";
2724
import * as WeakSpot from "../../test/weak-spot";
@@ -160,20 +157,12 @@ export async function onInsertText(options: OnInsertTextParams): Promise<void> {
160157
Config.oppositeShiftMode === "off" ? null : isCorrectShiftUsed();
161158

162159
// is char correct
163-
const funboxCorrect = findSingleActiveFunboxWithFunction(
164-
"isCharCorrect",
165-
)?.functions.isCharCorrect(
160+
const charCorrect = isCharCorrect({
166161
data,
167-
currentWord[(testInput + data).length - 1] ?? "",
168-
);
169-
const charCorrect =
170-
funboxCorrect ??
171-
isCharCorrect({
172-
data,
173-
inputValue: testInput,
174-
targetWord: currentWord,
175-
correctShiftUsed,
176-
});
162+
inputValue: testInput,
163+
targetWord: currentWord,
164+
correctShiftUsed,
165+
});
177166

178167
// word navigation check
179168
const noSpaceForce =
@@ -186,13 +175,12 @@ export async function onInsertText(options: OnInsertTextParams): Promise<void> {
186175
// when moving to the next word, correctness is word-level (a correct word-completing
187176
// space has charCorrect === false, so charCorrect can't be used below)
188177
const correct = goingToNextWord
189-
? (funboxCorrect ??
190-
isWordCorrect({
178+
? isWordCorrect({
191179
data,
192180
inputValue: testInput,
193181
targetWord: currentWord,
194182
correctShiftUsed,
195-
}))
183+
})
196184
: charCorrect;
197185

198186
// handing cases where last char needs to be removed

frontend/src/ts/test/funbox/funbox-functions.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export type FunboxFunctions = {
4242
pullSection?: (language?: Language) => Promise<JSONData.Section | false>;
4343
handleSpace?: () => void;
4444
getEmulatedChar?: (event: KeyboardEvent) => string | null;
45-
isCharCorrect?: (char: string, originalChar: string) => boolean;
4645
handleKeydown?: (event: KeyboardEvent) => Promise<void>;
4746
getResultContent?: () => string;
4847
start?: () => void;
@@ -261,42 +260,6 @@ const list: Partial<Record<FunboxName, FunboxFunctions>> = {
261260
}
262261
return null;
263262
},
264-
isCharCorrect(char: string, originalChar: string): boolean {
265-
if (
266-
(char === "a" ||
267-
char === "ArrowLeft" ||
268-
char === "j" ||
269-
char === "←") &&
270-
originalChar === "←"
271-
) {
272-
return true;
273-
}
274-
if (
275-
(char === "s" ||
276-
char === "ArrowDown" ||
277-
char === "k" ||
278-
char === "↓") &&
279-
originalChar === "↓"
280-
) {
281-
return true;
282-
}
283-
if (
284-
(char === "w" || char === "ArrowUp" || char === "i" || char === "↑") &&
285-
originalChar === "↑"
286-
) {
287-
return true;
288-
}
289-
if (
290-
(char === "d" ||
291-
char === "ArrowRight" ||
292-
char === "l" ||
293-
char === "→") &&
294-
originalChar === "→"
295-
) {
296-
return true;
297-
}
298-
return false;
299-
},
300263
getWordHtml(char: string, letterTag?: boolean): string {
301264
let retval = "";
302265
if (char === "↑") {

packages/funbox/src/list.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ const list: Record<FunboxName, FunboxMetadata> = {
108108
"getWord",
109109
"rememberSettings",
110110
"getEmulatedChar",
111-
"isCharCorrect",
112111
"getWordHtml",
113112
],
114113
name: "arrows",

packages/funbox/src/validation.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,6 @@ export function checkCompatibility(
178178
funboxesToCheck.filter((f) =>
179179
f.frontendFunctions?.includes("getEmulatedChar"),
180180
).length <= 1;
181-
const oneCharCheckerMax =
182-
funboxesToCheck.filter((f) =>
183-
f.frontendFunctions?.includes("isCharCorrect"),
184-
).length <= 1;
185181
const oneCharReplacerMax =
186182
funboxesToCheck.filter((f) => f.frontendFunctions?.includes("getWordHtml"))
187183
.length <= 1;
@@ -240,7 +236,6 @@ export function checkCompatibility(
240236
oneToPushOrPullSectionMax &&
241237
onePunctuateWordMax &&
242238
oneGetEmulatedCharMax &&
243-
oneCharCheckerMax &&
244239
oneCharReplacerMax &&
245240
oneChangesCapitalisationMax &&
246241
oneCssModificationPerElement &&

0 commit comments

Comments
 (0)