move lazyKeymaps definition to the base init

This commit is contained in:
tophf 2021-04-24 16:26:14 +03:00
parent 23aa036db5
commit b0a03d53fc

View File

@ -24,6 +24,10 @@ const editor = {
dirty: DirtyReporter(), dirty: DirtyReporter(),
isUsercss: false, isUsercss: false,
isWindowed: false, isWindowed: false,
lazyKeymaps: {
emacs: '/vendor/codemirror/keymap/emacs',
vim: '/vendor/codemirror/keymap/vim',
},
livePreview: null, livePreview: null,
/** @type {'customName'|'name'} */ /** @type {'customName'|'name'} */
nameTarget: 'name', nameTarget: 'name',
@ -43,10 +47,6 @@ const editor = {
//#region pre-init //#region pre-init
const baseInit = (() => { const baseInit = (() => {
const lazyKeymaps = {
emacs: '/vendor/codemirror/keymap/emacs',
vim: '/vendor/codemirror/keymap/vim',
};
const domReady = waitForSelector('#sections'); const domReady = waitForSelector('#sections');
return { return {
@ -65,8 +65,8 @@ const baseInit = (() => {
/** Preloads vim/emacs keymap only if it's the active one, otherwise will load later */ /** Preloads vim/emacs keymap only if it's the active one, otherwise will load later */
function loadKeymaps() { function loadKeymaps() {
const km = prefs.get('editor.keyMap'); const km = prefs.get('editor.keyMap');
return /emacs/i.test(km) && require([lazyKeymaps.emacs]) || return /emacs/i.test(km) && require([editor.lazyKeymaps.emacs]) ||
/vim/i.test(km) && require([lazyKeymaps.vim]); /vim/i.test(km) && require([editor.lazyKeymaps.vim]);
} }
async function loadStyle() { async function loadStyle() {
@ -83,7 +83,6 @@ const baseInit = (() => {
}; };
// switching the mode here to show the correct page ASAP, usually before DOMContentLoaded // switching the mode here to show the correct page ASAP, usually before DOMContentLoaded
editor.isUsercss = Boolean(style.usercssData || !style.id && prefs.get('newStyleAsUsercss')); editor.isUsercss = Boolean(style.usercssData || !style.id && prefs.get('newStyleAsUsercss'));
editor.lazyKeymaps = lazyKeymaps;
editor.style = style; editor.style = style;
editor.updateTitle(false); editor.updateTitle(false);
document.documentElement.classList.toggle('usercss', editor.isUsercss); document.documentElement.classList.toggle('usercss', editor.isUsercss);