@@ -35,7 +35,11 @@ import { ModifierKeys } from "../constants/modifier-keys";
3535import { navigate } from "./route-controller" ;
3636import * as Loader from "../elements/loader" ;
3737import * as KeyConverter from "../utils/key-converter" ;
38- import { getActiveFunboxes } from "../test/funbox/list" ;
38+ import {
39+ findSingleActiveFunboxWithFunction ,
40+ getFunctionsFromActiveFunboxes ,
41+ isFunboxActiveWithProperty ,
42+ } from "../test/funbox/list" ;
3943
4044let dontInsertSpace = false ;
4145let correctShiftUsed = true ;
@@ -145,7 +149,7 @@ function backspaceToPrevious(): void {
145149
146150 TestInput . input . current = TestInput . input . popHistory ( ) ;
147151 TestInput . corrected . popHistory ( ) ;
148- if ( getActiveFunboxes ( ) . find ( ( f ) => f . properties ?. includes ( "nospace" ) ) ) {
152+ if ( isFunboxActiveWithProperty ( "nospace" ) ) {
149153 TestInput . input . current = TestInput . input . current . slice ( 0 , - 1 ) ;
150154 setWordsInput ( " " + TestInput . input . current + " " ) ;
151155 }
@@ -194,8 +198,8 @@ async function handleSpace(): Promise<void> {
194198
195199 const currentWord : string = TestWords . words . getCurrent ( ) ;
196200
197- for ( const fb of getActiveFunboxes ( ) ) {
198- fb . functions ?. handleSpace ?. ( ) ;
201+ for ( const handleSpace of getFunctionsFromActiveFunboxes ( "handleSpace" ) ) {
202+ handleSpace ( ) ;
199203 }
200204
201205 dontInsertSpace = true ;
@@ -204,9 +208,7 @@ async function handleSpace(): Promise<void> {
204208 void LiveBurst . update ( Math . round ( burst ) ) ;
205209 TestInput . pushBurstToHistory ( burst ) ;
206210
207- const nospace =
208- getActiveFunboxes ( ) . find ( ( f ) => f . properties ?. includes ( "nospace" ) ) !==
209- undefined ;
211+ const nospace = isFunboxActiveWithProperty ( "nospace" ) ;
210212
211213 //correct word or in zen mode
212214 const isWordCorrect : boolean =
@@ -406,8 +408,8 @@ function isCharCorrect(char: string, charIndex: number): boolean {
406408 return true ;
407409 }
408410
409- const funbox = getActiveFunboxes ( ) . find ( ( fb ) => fb . functions ?. isCharCorrect ) ;
410- if ( funbox ?. functions ?. isCharCorrect ) {
411+ const funbox = findSingleActiveFunboxWithFunction ( " isCharCorrect" ) ;
412+ if ( funbox ) {
411413 return funbox . functions . isCharCorrect ( char , originalChar ) ;
412414 }
413415
@@ -492,15 +494,11 @@ function handleChar(
492494
493495 const isCharKorean : boolean = TestInput . input . getKoreanStatus ( ) ;
494496
495- for ( const fb of getActiveFunboxes ( ) ) {
496- if ( fb . functions ?. handleChar ) {
497- char = fb . functions . handleChar ( char ) ;
498- }
497+ for ( const handleChar of getFunctionsFromActiveFunboxes ( "handleChar" ) ) {
498+ char = handleChar ( char ) ;
499499 }
500500
501- const nospace =
502- getActiveFunboxes ( ) . find ( ( f ) => f . properties ?. includes ( "nospace" ) ) !==
503- undefined ;
501+ const nospace = isFunboxActiveWithProperty ( "nospace" ) !== undefined ;
504502
505503 if ( char !== "\n" && char !== "\t" && / \s / . test ( char ) ) {
506504 if ( nospace ) return ;
@@ -904,10 +902,8 @@ $(document).on("keydown", async (event) => {
904902 return ;
905903 }
906904
907- for ( const fb of getActiveFunboxes ( ) ) {
908- if ( fb . functions ?. handleKeydown ) {
909- void fb . functions . handleKeydown ( event ) ;
910- }
905+ for ( const handleKeydown of getFunctionsFromActiveFunboxes ( "handleKeydown" ) ) {
906+ void handleKeydown ( event ) ;
911907 }
912908
913909 //autofocus
@@ -1157,20 +1153,20 @@ $(document).on("keydown", async (event) => {
11571153 }
11581154 }
11591155
1160- for ( const fb of getActiveFunboxes ( ) ) {
1161- if ( fb . functions ?. preventDefaultEvent ) {
1162- if (
1163- await fb . functions . preventDefaultEvent (
1164- //i cant figure this type out, but it works fine
1165- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1166- event as JQuery . KeyDownEvent
1167- )
1168- ) {
1169- event . preventDefault ( ) ;
1170- handleChar ( event . key , TestInput . input . current . length ) ;
1171- updateUI ( ) ;
1172- setWordsInput ( " " + TestInput . input . current ) ;
1173- }
1156+ for ( const preventDefaultEvent of getFunctionsFromActiveFunboxes (
1157+ " preventDefaultEvent"
1158+ ) ) {
1159+ if (
1160+ await preventDefaultEvent (
1161+ //i cant figure this type out, but it works fine
1162+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1163+ event as JQuery . KeyDownEvent
1164+ )
1165+ ) {
1166+ event . preventDefault ( ) ;
1167+ handleChar ( event . key , TestInput . input . current . length ) ;
1168+ updateUI ( ) ;
1169+ setWordsInput ( " " + TestInput . input . current ) ;
11741170 }
11751171 }
11761172
0 commit comments