Skip to content

Commit 1e575f9

Browse files
committed
fix codemirrorr bug with debouncer again
1 parent 7c822b1 commit 1e575f9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

client/modules/IDE/components/Editor/codemirror.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ export default function useCodeMirror({
5656
const cmInstance = useRef();
5757

5858
function onKeyUp() {
59-
console.log('keyup');
6059
const lineNumber = parseInt(cmInstance.current.getCursor().line + 1, 10);
6160
setCurrentLine(lineNumber);
6261
}
6362

6463
function onKeyDown(_cm, e) {
65-
console.log('keydown');
6664
// Show hint
6765
const mode = cmInstance.current.getOption('mode');
6866
if (/^[a-z]$/i.test(e.key) && (mode === 'css' || mode === 'javascript')) {
@@ -82,11 +80,15 @@ export default function useCodeMirror({
8280
}
8381
}
8482

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+
8588
function onChange() {
86-
console.log('change');
8789
setUnsavedChanges(true);
8890
hideRuntimeErrorWarning();
89-
updateFileContent(file.id, cmInstance.current.getValue());
91+
updateFileContent(fileId.current, cmInstance.current.getValue());
9092
if (autorefresh && isPlaying) {
9193
clearConsole();
9294
startSketch();
@@ -189,7 +191,7 @@ export default function useCodeMirror({
189191

190192
function teardownCodeMirror() {
191193
cmInstance.current.off('keyup', onKeyUp);
192-
cmInstance.current.off('change', onChange);
194+
cmInstance.current.off('change', debouncedOnChange);
193195
cmInstance.current.off('keydown', onKeyDown);
194196
}
195197

0 commit comments

Comments
 (0)