@@ -379,22 +379,54 @@ FunboxList.setFunboxFunctions("specials", {
379379 } ,
380380} ) ;
381381
382+ async function readAheadHandleKeydown (
383+ event : JQuery . KeyDownEvent < Document , undefined , Document , Document >
384+ ) : Promise < void > {
385+ const inputCurrentChar = ( TestInput . input . current ?? "" ) . slice ( - 1 ) ;
386+ const wordCurrentChar = TestWords . words
387+ . getCurrent ( )
388+ . slice ( TestInput . input . current . length - 1 , TestInput . input . current . length ) ;
389+ const isCorrect = inputCurrentChar === wordCurrentChar ;
390+
391+ if (
392+ event . key == "Backspace" &&
393+ ! isCorrect &&
394+ ( TestInput . input . current != "" ||
395+ TestInput . input . history [ TestWords . words . currentIndex - 1 ] !=
396+ TestWords . words . get ( TestWords . words . currentIndex - 1 ) ||
397+ Config . freedomMode )
398+ ) {
399+ $ ( "#words" ) . addClass ( "read_ahead_disabled" ) ;
400+ } else if ( event . key == " " ) {
401+ $ ( "#words" ) . removeClass ( "read_ahead_disabled" ) ;
402+ }
403+ }
404+
382405FunboxList . setFunboxFunctions ( "read_ahead_easy" , {
383406 rememberSettings ( ) : void {
384407 save ( "highlightMode" , Config . highlightMode , UpdateConfig . setHighlightMode ) ;
385408 } ,
409+ async handleKeydown ( event ) : Promise < void > {
410+ await readAheadHandleKeydown ( event ) ;
411+ } ,
386412} ) ;
387413
388414FunboxList . setFunboxFunctions ( "read_ahead" , {
389415 rememberSettings ( ) : void {
390416 save ( "highlightMode" , Config . highlightMode , UpdateConfig . setHighlightMode ) ;
391417 } ,
418+ async handleKeydown ( event ) : Promise < void > {
419+ await readAheadHandleKeydown ( event ) ;
420+ } ,
392421} ) ;
393422
394423FunboxList . setFunboxFunctions ( "read_ahead_hard" , {
395424 rememberSettings ( ) : void {
396425 save ( "highlightMode" , Config . highlightMode , UpdateConfig . setHighlightMode ) ;
397426 } ,
427+ async handleKeydown ( event ) : Promise < void > {
428+ await readAheadHandleKeydown ( event ) ;
429+ } ,
398430} ) ;
399431
400432FunboxList . setFunboxFunctions ( "memory" , {
0 commit comments