@@ -56,11 +56,13 @@ export default function useCodeMirror({
56
56
const cmInstance = useRef ( ) ;
57
57
58
58
function onKeyUp ( ) {
59
+ console . log ( 'keyup' ) ;
59
60
const lineNumber = parseInt ( cmInstance . current . getCursor ( ) . line + 1 , 10 ) ;
60
61
setCurrentLine ( lineNumber ) ;
61
62
}
62
63
63
64
function onKeyDown ( _cm , e ) {
65
+ console . log ( 'keydown' ) ;
64
66
// Show hint
65
67
const mode = cmInstance . current . getOption ( 'mode' ) ;
66
68
if ( / ^ [ a - z ] $ / i. test ( e . key ) && ( mode === 'css' || mode === 'javascript' ) ) {
@@ -81,16 +83,16 @@ export default function useCodeMirror({
81
83
}
82
84
83
85
function onChange ( ) {
84
- debounce ( ( ) => {
85
- setUnsavedChanges ( true ) ;
86
- hideRuntimeErrorWarning ( ) ;
87
- updateFileContent ( file . id , cmInstance . current . getValue ( ) ) ;
88
- if ( autorefresh && isPlaying ) {
89
- clearConsole ( ) ;
90
- startSketch ( ) ;
91
- }
92
- } , 1000 ) ;
86
+ console . log ( 'change' ) ;
87
+ setUnsavedChanges ( true ) ;
88
+ hideRuntimeErrorWarning ( ) ;
89
+ updateFileContent ( file . id , cmInstance . current . getValue ( ) ) ;
90
+ if ( autorefresh && isPlaying ) {
91
+ clearConsole ( ) ;
92
+ startSketch ( ) ;
93
+ }
93
94
}
95
+ const debouncedOnChange = debounce ( onChange , 1000 ) ;
94
96
95
97
function setupCodeMirrorOnContainerMounted ( container ) {
96
98
cmInstance . current = CodeMirror ( container , {
@@ -161,7 +163,8 @@ export default function useCodeMirror({
161
163
[ `${ metaKey } -.` ] : 'toggleComment' // Note: most adblockers use the shortcut ctrl+.
162
164
} ) ;
163
165
164
- cmInstance . current . on ( 'change' , onChange ) ;
166
+ console . log ( 'setting up change handlers??' , cmInstance . current ) ;
167
+ cmInstance . current . on ( 'change' , debouncedOnChange ) ;
165
168
cmInstance . current . on ( 'keyup' , onKeyUp ) ;
166
169
cmInstance . current . on ( 'keydown' , onKeyDown ) ;
167
170
0 commit comments