@@ -52,31 +52,17 @@ function file_type(file: Item) {
52
52
}
53
53
54
54
const tab_behaviour = new Compartment ( ) ;
55
+ const vim_mode = new Compartment ( ) ;
55
56
56
57
const default_extensions = [
57
58
basicSetup ,
58
59
EditorState . tabSize . of ( 2 ) ,
59
60
tab_behaviour . of ( keymap . of ( [ { key : 'Tab' , run : acceptCompletion } ] ) ) ,
60
61
indentUnit . of ( '\t' ) ,
61
- theme
62
+ theme ,
63
+ vim_mode . of ( [ ] )
62
64
] ;
63
65
64
- // TODO add vim mode via a compartment (https://codemirror.net/examples/config/)
65
- // let installed_vim = false;
66
- // let should_install_vim = localStorage.getItem('vim') === 'true';
67
-
68
- // const q = new URLSearchParams(location.search);
69
- // if (q.has('vim')) {
70
- // should_install_vim = q.get('vim') === 'true';
71
- // localStorage.setItem('vim', should_install_vim.toString());
72
- // }
73
-
74
- // if (!installed_vim && should_install_vim) {
75
- // installed_vim = true;
76
- // const { vim } = await import('@replit/codemirror-vim');
77
- // extensions.push(vim());
78
- // }
79
-
80
66
export interface ExposedCompilerOptions {
81
67
generate : 'client' | 'server' ;
82
68
dev : boolean ;
@@ -243,11 +229,27 @@ export class Workspace {
243
229
this . modified = { } ;
244
230
}
245
231
246
- link ( view : EditorView ) {
232
+ async link ( view : EditorView ) {
247
233
if ( this . #view) throw new Error ( 'view is already linked' ) ;
248
234
this . #view = view ;
249
235
250
236
view . setState ( this . #get_state( untrack ( ( ) => this . #current) ) ) ;
237
+
238
+ let should_install_vim = localStorage . getItem ( 'vim' ) === 'true' ;
239
+
240
+ const q = new URLSearchParams ( location . search ) ;
241
+ if ( q . has ( 'vim' ) ) {
242
+ should_install_vim = q . get ( 'vim' ) === 'true' ;
243
+ localStorage . setItem ( 'vim' , should_install_vim . toString ( ) ) ;
244
+ }
245
+
246
+ if ( should_install_vim ) {
247
+ const { vim } = await import ( '@replit/codemirror-vim' ) ;
248
+
249
+ this . #view?. dispatch ( {
250
+ effects : vim_mode . reconfigure ( vim ( ) )
251
+ } ) ;
252
+ }
251
253
}
252
254
253
255
move ( from : Item , to : Item ) {
0 commit comments