11import { Compartment , EditorState , Extension } from "@codemirror/state" ;
2- import { EditorView , lineNumbers , keymap } from "@codemirror/view" ; // Add standardKeymap, defaultKeymap
3- import { defaultKeymap , standardKeymap } from "@codemirror/commands" ;
2+ import { EditorView , keymap , lineNumbers } from "@codemirror/view" ;
3+ import { defaultKeymap , standardKeymap , toggleComment } from "@codemirror/commands" ;
44import { html } from "@codemirror/lang-html" ;
55import { css } from "@codemirror/lang-css" ;
66import { javascript } from "@codemirror/lang-javascript" ;
7- import { linter , lintGutter } from "@codemirror/lint" ;
7+ import { autocompletion } from "@codemirror/autocomplete" ;
8+ import { foldGutter , foldKeymap } from "@codemirror/language" ;
9+ import { formatCode } from "./runner" ;
810import { monokai } from "@uiw/codemirror-theme-monokai" ;
911import { bbedit } from "@uiw/codemirror-theme-bbedit" ;
1012import { CodeMirrorEditor , Editors } from "./types" ;
@@ -13,7 +15,6 @@ import { toggleSearch } from "./main";
1315import { debounce } from "./utils" ;
1416import { autoRunState , cssState , darkModeState , htmlState , jsState } from "./appState" ;
1517import { search } from "@codemirror/search" ;
16- import { toggleComment } from "@codemirror/commands" ; // Ensure toggleComment is imported
1718
1819export const editors : Editors = {
1920 html : null as unknown as CodeMirrorEditor ,
@@ -34,10 +35,17 @@ export function setDarkMode(value: boolean): void {
3435
3536export function setAutoRun ( value : boolean ) : void {
3637 autoRunState . set ( value ) ;
38+ Object . values ( editors ) . forEach ( ( editor ) => {
39+ editor . view . dispatch ( {
40+ effects : editor . autoRunCompartment . reconfigure (
41+ value ? autoRunListener : [ ]
42+ ) ,
43+ } ) ;
44+ } ) ;
3745}
3846
3947// Shared debounced runner used by auto-run listeners so debounce state is preserved across keystrokes
40- const debouncedRun = debounce ( runCode , 1000 ) ;
48+ const debouncedRun = debounce ( runCode , 250 ) ;
4149export const autoRunListener = EditorView . updateListener . of ( ( update ) => {
4250 if ( update . docChanged ) debouncedRun ( ) ;
4351} ) ;
@@ -56,6 +64,7 @@ function createEditorConfig(
5664 doc : content ,
5765 extensions : [
5866 lineNumbers ( ) ,
67+ foldGutter ( ) ,
5968 language ,
6069 themeCompartment . of ( darkModeState . get ( ) ? monokai : bbedit ) ,
6170 EditorView . lineWrapping ,
@@ -66,16 +75,9 @@ function createEditorConfig(
6675 ".cm-content" : { minHeight : "100%" }
6776 } ) ,
6877 search ( ) ,
69- linter (
70- ( view ) => {
71- return [ ] ;
72- } ,
73- { delay : 100 }
74- ) ,
75- lintGutter ( ) ,
7678 keymap . of ( [
7779 ...defaultKeymap ,
78- ...standardKeymap ,
80+ ...foldKeymap ,
7981 { key : "Mod-/" , run : toggleComment } ,
8082 ] ) ,
8183 autoRunCompartment . of ( autoRunState . get ( ) ? autoRunListener : [ ] ) ,
0 commit comments