diff --git a/edit/codemirror-editing-hooks.js b/edit/codemirror-editing-hooks.js index 80b0b13d..39773e45 100644 --- a/edit/codemirror-editing-hooks.js +++ b/edit/codemirror-editing-hooks.js @@ -33,6 +33,27 @@ onDOMscriptReady('/codemirror.js').then(() => { rerouteHotkeys, }); + CodeMirror.defineInitHook(cm => { + if (prefs.get('editor.livePreview')) { + cm.on('changes', updatePreview); + } + if (prefs.get('editor.autocompleteOnTyping')) { + setupAutocomplete(cm); + } + const wrapper = cm.display.wrapper; + cm.on('blur', () => { + editors.lastActive = cm; + cm.rerouteHotkeys(true); + setTimeout(() => { + wrapper.classList.toggle('CodeMirror-active', wrapper.contains(document.activeElement)); + }); + }); + cm.on('focus', () => { + cm.rerouteHotkeys(false); + wrapper.classList.add('CodeMirror-active'); + }); + }); + new MutationObserver((mutations, observer) => { if (!$('#sections')) { return; @@ -561,11 +582,6 @@ onDOMscriptReady('/codemirror.js').then(() => { updatePreview(null, previewing); } }; - CodeMirror.defineInitHook(cm => { - if (prefs.get('editor.livePreview')) { - cm.on('changes', updatePreview); - } - }); } function updatePreview(data, previewing) { diff --git a/edit/sections.js b/edit/sections.js index 0e88d500..577ff479 100644 --- a/edit/sections.js +++ b/edit/sections.js @@ -190,21 +190,7 @@ function setupCodeMirror(sectionDiv, code, index) { clearTimeout(onChangeTimer); onChangeTimer = setTimeout(indicateCodeChange, 200, cm, changes); }); - if (prefs.get('editor.autocompleteOnTyping')) { - setupAutocomplete(cm); - } wrapper.addEventListener('keydown', event => nextPrevEditorOnKeydown(cm, event), true); - cm.on('blur', () => { - editors.lastActive = cm; - cm.rerouteHotkeys(true); - setTimeout(() => { - wrapper.classList.toggle('CodeMirror-active', wrapper.contains(document.activeElement)); - }); - }); - cm.on('focus', () => { - cm.rerouteHotkeys(false); - wrapper.classList.add('CodeMirror-active'); - }); cm.on('paste', (cm, event) => { const text = event.clipboardData.getData('text') || ''; if ( diff --git a/edit/source-editor.js b/edit/source-editor.js index dd81521f..ab909b8c 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -44,9 +44,6 @@ function createSourceEditor(style) { updateLintReportIfEnabled(cm); }); - cm.on('focus', () => cm.rerouteHotkeys(false)); - cm.on('blur', () => cm.rerouteHotkeys(true)); - CodeMirror.commands.prevEditor = cm => nextPrevMozDocument(cm, -1); CodeMirror.commands.nextEditor = cm => nextPrevMozDocument(cm, 1); CodeMirror.commands.toggleStyle = toggleStyle;