Skip to content

Commit 7c822b1

Browse files
committed
fix codemirror file debounce bug
1 parent 55bb4a5 commit 7c822b1

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

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

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

5858
function onKeyUp() {
59+
console.log('keyup');
5960
const lineNumber = parseInt(cmInstance.current.getCursor().line + 1, 10);
6061
setCurrentLine(lineNumber);
6162
}
6263

6364
function onKeyDown(_cm, e) {
65+
console.log('keydown');
6466
// Show hint
6567
const mode = cmInstance.current.getOption('mode');
6668
if (/^[a-z]$/i.test(e.key) && (mode === 'css' || mode === 'javascript')) {
@@ -81,16 +83,16 @@ export default function useCodeMirror({
8183
}
8284

8385
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+
}
9394
}
95+
const debouncedOnChange = debounce(onChange, 1000);
9496

9597
function setupCodeMirrorOnContainerMounted(container) {
9698
cmInstance.current = CodeMirror(container, {
@@ -161,7 +163,8 @@ export default function useCodeMirror({
161163
[`${metaKey}-.`]: 'toggleComment' // Note: most adblockers use the shortcut ctrl+.
162164
});
163165

164-
cmInstance.current.on('change', onChange);
166+
console.log('setting up change handlers??', cmInstance.current);
167+
cmInstance.current.on('change', debouncedOnChange);
165168
cmInstance.current.on('keyup', onKeyUp);
166169
cmInstance.current.on('keydown', onKeyDown);
167170

0 commit comments

Comments
 (0)