Fix: don't reinit all editors on save

This commit is contained in:
eight 2018-10-12 16:27:54 +08:00
parent 1a5a206fe6
commit 5ae95a1ad9
2 changed files with 23 additions and 7 deletions

View File

@ -122,6 +122,7 @@ function createSection({
getCode, getCode,
getModel, getModel,
remove, remove,
destroy,
restore, restore,
isRemoved: () => removed, isRemoved: () => removed,
onChange, onChange,
@ -271,14 +272,15 @@ function createSection({
return cm.getValue(); return cm.getValue();
} }
function remove(destroy = false) { function remove() {
linter.disableForEditor(cm); linter.disableForEditor(cm);
el.classList.add('removed'); el.classList.add('removed');
removed = true; removed = true;
appliesTo.forEach(a => a.remove()); appliesTo.forEach(a => a.remove());
if (destroy) { }
cmFactory.destroy(cm);
} function destroy() {
cmFactory.destroy(cm);
} }
function restore() { function restore() {

View File

@ -406,11 +406,24 @@ function createSectionsEditor(style) {
} }
API.editSave(newStyle) API.editSave(newStyle)
.then(newStyle => { .then(newStyle => {
destroyRemovedSections();
sessionStorage.justEditedStyleId = newStyle.id; 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() { function updateHeader() {
nameEl.value = style.name || ''; nameEl.value = style.name || '';
enabledEl.checked = style.enabled !== false; enabledEl.checked = style.enabled !== false;
@ -476,7 +489,8 @@ function createSectionsEditor(style) {
const index = sections.indexOf(section); const index = sections.indexOf(section);
sections.splice(index, 1); sections.splice(index, 1);
section.el.remove(); section.el.remove();
section.remove(true); section.remove();
section.destroy();
} else { } else {
const lines = []; const lines = [];
const MAX_LINES = 10; const MAX_LINES = 10;
@ -486,7 +500,7 @@ function createSectionsEditor(style) {
lines.slice(0, MAX_LINES).map(s => clipString(s, 100)).join('\n') + lines.slice(0, MAX_LINES).map(s => clipString(s, 100)).join('\n') +
(lines.length > MAX_LINES ? '\n...' : ''); (lines.length > MAX_LINES ? '\n...' : '');
$('.deleted-section', section.el).title = title; $('.deleted-section', section.el).title = title;
section.remove(false); section.remove();
} }
dirty.remove(section, section); dirty.remove(section, section);
updateSectionOrder(); updateSectionOrder();