simplify toggleEditorFocus now that CM 5.35 handles Ctrl-Pause

This commit is contained in:
tophf 2018-03-03 23:30:33 +03:00
parent 77d44c233e
commit 6e8ff5b9ef
2 changed files with 10 additions and 15 deletions

View File

@ -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 = {};

View File

@ -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)) {