@@ -56,13 +56,11 @@ export default function useCodeMirror({
56
56
const cmInstance = useRef ( ) ;
57
57
58
58
function onKeyUp ( ) {
59
- console . log ( 'keyup' ) ;
60
59
const lineNumber = parseInt ( cmInstance . current . getCursor ( ) . line + 1 , 10 ) ;
61
60
setCurrentLine ( lineNumber ) ;
62
61
}
63
62
64
63
function onKeyDown ( _cm , e ) {
65
- console . log ( 'keydown' ) ;
66
64
// Show hint
67
65
const mode = cmInstance . current . getOption ( 'mode' ) ;
68
66
if ( / ^ [ a - z ] $ / i. test ( e . key ) && ( mode === 'css' || mode === 'javascript' ) ) {
@@ -82,11 +80,15 @@ export default function useCodeMirror({
82
80
}
83
81
}
84
82
83
+ // We have to create a ref for the file ID, or else the debouncer
84
+ // will old onto an old version of the fileId and just overrwrite the initial file.
85
+ const fileId = useRef ( ) ;
86
+ fileId . current = file . id ;
87
+
85
88
function onChange ( ) {
86
- console . log ( 'change' ) ;
87
89
setUnsavedChanges ( true ) ;
88
90
hideRuntimeErrorWarning ( ) ;
89
- updateFileContent ( file . id , cmInstance . current . getValue ( ) ) ;
91
+ updateFileContent ( fileId . current , cmInstance . current . getValue ( ) ) ;
90
92
if ( autorefresh && isPlaying ) {
91
93
clearConsole ( ) ;
92
94
startSketch ( ) ;
@@ -189,7 +191,7 @@ export default function useCodeMirror({
189
191
190
192
function teardownCodeMirror ( ) {
191
193
cmInstance . current . off ( 'keyup' , onKeyUp ) ;
192
- cmInstance . current . off ( 'change' , onChange ) ;
194
+ cmInstance . current . off ( 'change' , debouncedOnChange ) ;
193
195
cmInstance . current . off ( 'keydown' , onKeyDown ) ;
194
196
}
195
197
0 commit comments