Merge branch 'master' into uso2archive
This commit is contained in:
commit
7617a0a0b4
|
@ -21,19 +21,7 @@
|
||||||
|
|
||||||
create(place, options) {
|
create(place, options) {
|
||||||
const cm = CodeMirror(place, options);
|
const cm = CodeMirror(place, options);
|
||||||
const {wrapper} = cm.display;
|
|
||||||
cm.lastActive = 0;
|
cm.lastActive = 0;
|
||||||
cm.on('blur', () => {
|
|
||||||
rerouteHotkeys(true);
|
|
||||||
setTimeout(() => {
|
|
||||||
wrapper.classList.toggle('CodeMirror-active', wrapper.contains(document.activeElement));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
cm.on('focus', () => {
|
|
||||||
rerouteHotkeys(false);
|
|
||||||
wrapper.classList.add('CodeMirror-active');
|
|
||||||
cm.lastActive = Date.now();
|
|
||||||
});
|
|
||||||
cms.add(cm);
|
cms.add(cm);
|
||||||
return cm;
|
return cm;
|
||||||
},
|
},
|
||||||
|
@ -52,6 +40,23 @@
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onCmFocus = cm => {
|
||||||
|
rerouteHotkeys.toggle(false);
|
||||||
|
cm.display.wrapper.classList.add('CodeMirror-active');
|
||||||
|
cm.lastActive = Date.now();
|
||||||
|
};
|
||||||
|
const onCmBlur = cm => {
|
||||||
|
rerouteHotkeys.toggle(true);
|
||||||
|
setTimeout(() => {
|
||||||
|
const {wrapper} = cm.display;
|
||||||
|
wrapper.classList.toggle('CodeMirror-active', wrapper.contains(document.activeElement));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
CodeMirror.defineInitHook(cm => {
|
||||||
|
cm.on('focus', onCmFocus);
|
||||||
|
cm.on('blur', onCmBlur);
|
||||||
|
});
|
||||||
|
|
||||||
const handledPrefs = {
|
const handledPrefs = {
|
||||||
'editor.colorpicker'() {}, // handled in colorpicker-helper.js
|
'editor.colorpicker'() {}, // handled in colorpicker-helper.js
|
||||||
async 'editor.theme'(key, value) {
|
async 'editor.theme'(key, value) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* global $ $create $createLink messageBoxProxy */// dom.js
|
/* global $ $create $createLink messageBoxProxy */// dom.js
|
||||||
/* global chromeSync */// storage-util.js
|
/* global chromeSync */// storage-util.js
|
||||||
/* global editor */
|
/* global editor */
|
||||||
/* global helpPopup rerouteHotkeys showCodeMirrorPopup */// util.js
|
/* global helpPopup showCodeMirrorPopup */// util.js
|
||||||
/* global linterMan */
|
/* global linterMan */
|
||||||
/* global t */// localization.js
|
/* global t */// localization.js
|
||||||
/* global tryJSONparse */// toolbox.js
|
/* global tryJSONparse */// toolbox.js
|
||||||
|
@ -62,7 +62,6 @@
|
||||||
cm.focus();
|
cm.focus();
|
||||||
cm.on('changes', updateConfigButtons);
|
cm.on('changes', updateConfigButtons);
|
||||||
updateConfigButtons();
|
updateConfigButtons();
|
||||||
rerouteHotkeys(false);
|
|
||||||
window.on('closeHelp', onConfigClose, {once: true});
|
window.on('closeHelp', onConfigClose, {once: true});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -160,7 +159,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function onConfigClose() {
|
function onConfigClose() {
|
||||||
rerouteHotkeys(true);
|
|
||||||
cm = null;
|
cm = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ function SectionsEditor() {
|
||||||
let headerOffset; // in compact mode the header is at the top so it reduces the available height
|
let headerOffset; // in compact mode the header is at the top so it reduces the available height
|
||||||
|
|
||||||
updateHeader();
|
updateHeader();
|
||||||
|
rerouteHotkeys.toggle(true); // enabled initially because we don't always focus a CodeMirror
|
||||||
editor.livePreview.init(null, style.id);
|
editor.livePreview.init(null, style.id);
|
||||||
container.classList.add('section-editor');
|
container.classList.add('section-editor');
|
||||||
$('#to-mozilla').on('click', showMozillaFormat);
|
$('#to-mozilla').on('click', showMozillaFormat);
|
||||||
|
@ -53,7 +54,8 @@ function SectionsEditor() {
|
||||||
},
|
},
|
||||||
|
|
||||||
getSearchableInputs(cm) {
|
getSearchableInputs(cm) {
|
||||||
return sections.find(s => s.cm === cm).appliesTo.map(a => a.valueEl).filter(Boolean);
|
const sec = sections.find(s => s.cm === cm);
|
||||||
|
return sec ? sec.appliesTo.map(a => a.valueEl).filter(Boolean) : [];
|
||||||
},
|
},
|
||||||
|
|
||||||
jumpToEditor(i) {
|
jumpToEditor(i) {
|
||||||
|
@ -488,7 +490,6 @@ function SectionsEditor() {
|
||||||
scrollTo(0, si.scrollY);
|
scrollTo(0, si.scrollY);
|
||||||
// only restore focus if it's the first CM to avoid derpy quirks
|
// only restore focus if it's the first CM to avoid derpy quirks
|
||||||
focusOn = si.cms[0].focus && 0;
|
focusOn = si.cms[0].focus && 0;
|
||||||
rerouteHotkeys(true);
|
|
||||||
} else {
|
} else {
|
||||||
si = null;
|
si = null;
|
||||||
}
|
}
|
||||||
|
|
15
edit/util.js
15
edit/util.js
|
@ -1,6 +1,5 @@
|
||||||
/* global $ $create getEventKeyName messageBoxProxy moveFocus */// dom.js
|
/* global $ $create getEventKeyName messageBoxProxy moveFocus */// dom.js
|
||||||
/* global CodeMirror */
|
/* global CodeMirror */
|
||||||
/* global debounce */// toolbox.js
|
|
||||||
/* global editor */
|
/* global editor */
|
||||||
/* global prefs */
|
/* global prefs */
|
||||||
/* global t */// localization.js
|
/* global t */// localization.js
|
||||||
|
@ -59,7 +58,7 @@ const helpPopup = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// reroute handling to nearest editor when keypress resolves to one of these commands
|
// reroute handling to nearest editor when keypress resolves to one of these commands
|
||||||
Object.assign(rerouteHotkeys, {
|
const rerouteHotkeys = {
|
||||||
commands: [
|
commands: [
|
||||||
'beautify',
|
'beautify',
|
||||||
'colorpicker',
|
'colorpicker',
|
||||||
|
@ -97,7 +96,7 @@ Object.assign(rerouteHotkeys, {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
|
||||||
function clipString(str, limit = 100) {
|
function clipString(str, limit = 100) {
|
||||||
return str.length <= limit ? str : str.substr(0, limit) + '...';
|
return str.length <= limit ? str : str.substr(0, limit) + '...';
|
||||||
|
@ -149,14 +148,6 @@ function createHotkeyInput(prefId, onDone = () => {}) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function rerouteHotkeys(enable, immediately) {
|
|
||||||
if (immediately) {
|
|
||||||
rerouteHotkeys.toggle(enable);
|
|
||||||
} else {
|
|
||||||
debounce(rerouteHotkeys.toggle, 0, enable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* exported showCodeMirrorPopup */
|
/* exported showCodeMirrorPopup */
|
||||||
function showCodeMirrorPopup(title, html, options) {
|
function showCodeMirrorPopup(title, html, options) {
|
||||||
const popup = helpPopup.show(title, html);
|
const popup = helpPopup.show(title, html);
|
||||||
|
@ -174,7 +165,6 @@ function showCodeMirrorPopup(title, html, options) {
|
||||||
keyMap: prefs.get('editor.keyMap'),
|
keyMap: prefs.get('editor.keyMap'),
|
||||||
}, options));
|
}, options));
|
||||||
cm.focus();
|
cm.focus();
|
||||||
rerouteHotkeys(false);
|
|
||||||
|
|
||||||
document.documentElement.style.pointerEvents = 'none';
|
document.documentElement.style.pointerEvents = 'none';
|
||||||
popup.style.pointerEvents = 'auto';
|
popup.style.pointerEvents = 'auto';
|
||||||
|
@ -192,7 +182,6 @@ function showCodeMirrorPopup(title, html, options) {
|
||||||
window.on('closeHelp', () => {
|
window.on('closeHelp', () => {
|
||||||
window.off('keydown', onKeyDown, true);
|
window.off('keydown', onKeyDown, true);
|
||||||
document.documentElement.style.removeProperty('pointer-events');
|
document.documentElement.style.removeProperty('pointer-events');
|
||||||
rerouteHotkeys(true);
|
|
||||||
cm = popup.codebox = null;
|
cm = popup.codebox = null;
|
||||||
}, {once: true});
|
}, {once: true});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user