Ctrl-Pause defocuses/focuses the editor

This commit is contained in:
tophf 2017-12-21 02:29:24 +03:00
parent 2d12bfd1f5
commit 2dfaa22c35

View File

@ -1,4 +1,4 @@
/* global CodeMirror prefs loadScript editor */
/* global CodeMirror prefs loadScript editor editors */
'use strict';
@ -27,7 +27,6 @@
keyMap: prefs.get('editor.keyMap'),
extraKeys: Object.assign(CodeMirror.defaults.extraKeys || {}, {
// independent of current keyMap
'Esc': 'defocusEditor',
'Alt-Enter': 'toggleStyle',
'Alt-PageDown': 'nextEditor',
'Alt-PageUp': 'prevEditor'
@ -41,6 +40,19 @@
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 = {};