diff --git a/edit/codemirror-default.js b/edit/codemirror-default.js index 816671ab..859a7625 100644 --- a/edit/codemirror-default.js +++ b/edit/codemirror-default.js @@ -30,8 +30,6 @@ 'Alt-Enter': 'toggleStyle', 'Alt-PageDown': 'nextEditor', 'Alt-PageUp': 'prevEditor', - // show the hotkey in keymap info popup by adding a dummy command - // TODO: implement as a normal command when CodeMirror is fixed 'Ctrl-Pause': 'toggleEditorFocus', }), maxHighlightLength: 100e3, @@ -44,19 +42,6 @@ cm.blockComment(cm.getCursor('from'), cm.getCursor('to'), {fullLines: false}); }; - // Ctrl-Pause defocuses/focuses the editor - addEventListener('keydown', event => { - if (event.code === 'Pause' && event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) { - event.preventDefault(); - const cm = window.editors && (editors.lastActive || editors[0]) || ($('.CodeMirror') || {}).CodeMirror; - if (cm && cm.hasFocus()) { - setTimeout(() => cm.display.input.blur()); - } else if (cm) { - cm.focus(); - } - } - }, true); - // 'basic' keymap only has basic keys by design, so we skip it const extraKeysCommands = {}; diff --git a/edit/codemirror-editing-hooks.js b/edit/codemirror-editing-hooks.js index dfe0b831..b2fe7ab3 100644 --- a/edit/codemirror-editing-hooks.js +++ b/edit/codemirror-editing-hooks.js @@ -14,6 +14,7 @@ onDOMscriptReady('/codemirror.js').then(() => { const COMMANDS = { save, toggleStyle, + toggleEditorFocus, jumpToLine, nextEditor, prevEditor, }; @@ -198,6 +199,15 @@ onDOMscriptReady('/codemirror.js').then(() => { }, {value: cur.line + 1}); } + function toggleEditorFocus(cm) { + if (!cm) return; + if (cm.hasFocus()) { + setTimeout(() => cm.display.input.blur()); + } else { + cm.focus(); + } + } + function refocusMinidialog(cm) { const section = cm.getSection(); if (!$('.CodeMirror-dialog', section)) {