diff --git a/edit/sections-editor-section.js b/edit/sections-editor-section.js index 32196633..cf29822f 100644 --- a/edit/sections-editor-section.js +++ b/edit/sections-editor-section.js @@ -122,6 +122,7 @@ function createSection({ getCode, getModel, remove, + destroy, restore, isRemoved: () => removed, onChange, @@ -271,14 +272,15 @@ function createSection({ return cm.getValue(); } - function remove(destroy = false) { + function remove() { linter.disableForEditor(cm); el.classList.add('removed'); removed = true; appliesTo.forEach(a => a.remove()); - if (destroy) { - cmFactory.destroy(cm); - } + } + + function destroy() { + cmFactory.destroy(cm); } function restore() { diff --git a/edit/sections-editor.js b/edit/sections-editor.js index c9b3421f..1fae9a07 100644 --- a/edit/sections-editor.js +++ b/edit/sections-editor.js @@ -406,11 +406,24 @@ function createSectionsEditor(style) { } API.editSave(newStyle) .then(newStyle => { + destroyRemovedSections(); sessionStorage.justEditedStyleId = newStyle.id; - replaceStyle(newStyle); + replaceStyle(newStyle, false); }); } + function destroyRemovedSections() { + for (let i = 0; i < sections.length;) { + if (!sections[i].isRemoved()) { + i++; + continue; + } + sections[i].destroy(); + sections[i].el.remove(); + sections.splice(i, 1); + } + } + function updateHeader() { nameEl.value = style.name || ''; enabledEl.checked = style.enabled !== false; @@ -476,7 +489,8 @@ function createSectionsEditor(style) { const index = sections.indexOf(section); sections.splice(index, 1); section.el.remove(); - section.remove(true); + section.remove(); + section.destroy(); } else { const lines = []; const MAX_LINES = 10; @@ -486,7 +500,7 @@ function createSectionsEditor(style) { lines.slice(0, MAX_LINES).map(s => clipString(s, 100)).join('\n') + (lines.length > MAX_LINES ? '\n...' : ''); $('.deleted-section', section.el).title = title; - section.remove(false); + section.remove(); } dirty.remove(section, section); updateSectionOrder();