@@ -468,20 +468,36 @@ export class Workspace {
468468 }
469469
470470 set vim ( value ) {
471+ this . #toggle_vim( value ) ;
472+ }
473+
474+ async #toggle_vim( value : boolean ) {
471475 this . #vim = value ;
472476
473477 localStorage . setItem ( 'vim' , String ( value ) ) ;
474478
479+ // @ts -expect-error jfc CodeMirror is a struggle
480+ let vim_extension_index = default_extensions . findIndex ( ( ext ) => ext . compartment === vim_mode ) ;
481+
482+ let extension : any = [ ] ;
483+
475484 if ( value ) {
476- import ( '@replit/codemirror-vim' ) . then ( ( { vim } ) => {
477- this . #view?. dispatch ( {
478- effects : vim_mode . reconfigure ( vim ( ) )
479- } ) ;
480- } ) ;
481- } else {
482- this . #view?. dispatch ( {
483- effects : vim_mode . reconfigure ( [ ] )
484- } ) ;
485+ const { vim } = await import ( '@replit/codemirror-vim' ) ;
486+ extension = vim ( ) ;
487+ }
488+
489+ default_extensions [ vim_extension_index ] = vim_mode . of ( extension ) ;
490+
491+ this . #view?. dispatch ( {
492+ effects : vim_mode . reconfigure ( extension )
493+ } ) ;
494+
495+ // update all the other states
496+ for ( const file of this . #files) {
497+ if ( file . type !== 'file' ) continue ;
498+ if ( file === this . #current) continue ;
499+
500+ this . states . set ( file . name , this . #create_state( file ) ) ;
485501 }
486502 }
487503
@@ -506,9 +522,10 @@ export class Workspace {
506522 }
507523
508524 #get_state( file : File ) {
509- let state = this . states . get ( file . name ) ;
510- if ( state ) return state ;
525+ return this . states . get ( file . name ) ?? this . #create_state ( file ) ;
526+ }
511527
528+ #create_state( file : File ) {
512529 const extensions = [
513530 ...default_extensions ,
514531 EditorState . readOnly . of ( this . #readonly) ,
@@ -582,7 +599,7 @@ export class Workspace {
582599 break ;
583600 }
584601
585- state = EditorState . create ( {
602+ const state = EditorState . create ( {
586603 doc : file . contents ,
587604 extensions
588605 } ) ;
0 commit comments