From 00866fb74048a62b5bc5c14fbb87c2b27f259b09 Mon Sep 17 00:00:00 2001 From: tophf Date: Wed, 30 Aug 2017 01:49:03 +0300 Subject: [PATCH] properly replace the editors in initWithStyle --- edit/edit.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/edit/edit.js b/edit/edit.js index 82a339de..7c4bdde6 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -1217,6 +1217,8 @@ function init() { // default to enabled $('#enabled').checked = true; initHooks(); + setCleanGlobal(); + updateTitle(); return; } // This is an edit @@ -1255,9 +1257,11 @@ function initWithStyle({style, codeIsUpdated}) { return; } // 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 queueStart = new Date().getTime(); + maximizeCodeHeight.stats = null; // after 100ms the sections will be added asynchronously while (new Date().getTime() - queueStart <= 100 && queue.length) { add(); @@ -1269,16 +1273,20 @@ function initWithStyle({style, codeIsUpdated}) { } })(); initHooks(); + setCleanGlobal(); + updateTitle(); function add() { const sectionDiv = addSection(null, queue.shift()); - const isLast = !queue.length; - maximizeCodeHeight(sectionDiv, isLast); - updateLintReport(sectionDiv.CodeMirror, !isLast && 100); + maximizeCodeHeight(sectionDiv, !queue.length); } } function initHooks() { + if (initHooks.alreadyDone) { + return; + } + initHooks.alreadyDone = true; $$('#header .style-contributor').forEach(node => { node.addEventListener('change', onChange); node.addEventListener('input', onChange); @@ -1310,8 +1318,6 @@ function initHooks() { }); setupGlobalSearch(); - setCleanGlobal(); - updateTitle(); }