properly replace the editors in initWithStyle

This commit is contained in:
tophf 2017-08-30 01:49:03 +03:00
parent d3ed4ced92
commit 00866fb740

View File

@ -1217,6 +1217,8 @@ function init() {
// default to enabled // default to enabled
$('#enabled').checked = true; $('#enabled').checked = true;
initHooks(); initHooks();
setCleanGlobal();
updateTitle();
return; return;
} }
// This is an edit // This is an edit
@ -1255,9 +1257,11 @@ function initWithStyle({style, codeIsUpdated}) {
return; return;
} }
// if this was done in response to an update, we need to clear existing sections // if this was done in response to an update, we need to clear existing sections
getSections().forEach(div => { div.remove(); }); editors.length = 0;
getSections().forEach(div => div.remove());
const queue = style.sections.length ? style.sections.slice() : [{code: ''}]; const queue = style.sections.length ? style.sections.slice() : [{code: ''}];
const queueStart = new Date().getTime(); const queueStart = new Date().getTime();
maximizeCodeHeight.stats = null;
// after 100ms the sections will be added asynchronously // after 100ms the sections will be added asynchronously
while (new Date().getTime() - queueStart <= 100 && queue.length) { while (new Date().getTime() - queueStart <= 100 && queue.length) {
add(); add();
@ -1269,16 +1273,20 @@ function initWithStyle({style, codeIsUpdated}) {
} }
})(); })();
initHooks(); initHooks();
setCleanGlobal();
updateTitle();
function add() { function add() {
const sectionDiv = addSection(null, queue.shift()); const sectionDiv = addSection(null, queue.shift());
const isLast = !queue.length; maximizeCodeHeight(sectionDiv, !queue.length);
maximizeCodeHeight(sectionDiv, isLast);
updateLintReport(sectionDiv.CodeMirror, !isLast && 100);
} }
} }
function initHooks() { function initHooks() {
if (initHooks.alreadyDone) {
return;
}
initHooks.alreadyDone = true;
$$('#header .style-contributor').forEach(node => { $$('#header .style-contributor').forEach(node => {
node.addEventListener('change', onChange); node.addEventListener('change', onChange);
node.addEventListener('input', onChange); node.addEventListener('input', onChange);
@ -1310,8 +1318,6 @@ function initHooks() {
}); });
setupGlobalSearch(); setupGlobalSearch();
setCleanGlobal();
updateTitle();
} }