From ab97108e6f5be989c0c7b514ed07050d21fa9441 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 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/edit/edit.js b/edit/edit.js index 8435deb8..b66ecb76 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -1247,6 +1247,8 @@ function init() { // default to enabled $('#enabled').checked = true; initHooks(); + setCleanGlobal(); + updateTitle(); return; } // This is an edit @@ -1285,9 +1287,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 t0 = performance.now(); + maximizeCodeHeight.stats = null; // after 100ms the sections will be added asynchronously while (performance.now() - t0 <= 100 && queue.length) { add(); @@ -1299,6 +1303,8 @@ function initWithStyle({style, codeIsUpdated}) { } })(); initHooks(); + setCleanGlobal(); + updateTitle(); function add() { const sectionDiv = addSection(null, queue.shift()); @@ -1310,6 +1316,10 @@ function initWithStyle({style, codeIsUpdated}) { } function initHooks() { + if (initHooks.alreadyDone) { + return; + } + initHooks.alreadyDone = true; $$('#header .style-contributor').forEach(node => { node.addEventListener('change', onChange); node.addEventListener('input', onChange); @@ -1341,8 +1351,6 @@ function initHooks() { }); setupGlobalSearch(); - setCleanGlobal(); - updateTitle(); }