Fix: replaceStyle make style name undefined

This commit is contained in:
eight 2018-10-12 15:30:35 +08:00
parent fa080d1913
commit 8016346035
3 changed files with 8 additions and 10 deletions

View File

@ -325,14 +325,12 @@ function onRuntimeMessage(request) {
request.reason !== 'editPreview' &&
request.reason !== 'editSave' &&
request.reason !== 'config') {
// code-less style from notifyAllTabs
const {sections, id} = request.style;
((sections && sections[0] || {}).code === null
? API.getStyle(id)
: Promise.resolve([request.style])
).then(([style]) => {
editor.replaceStyle(style, request.codeIsUpdated);
});
Promise.resolve(request.codeIsUpdated === false ?
request.style : API.getStyle(request.style.id)
)
.then(newStyle => {
editor.replaceStyle(newStyle, request.codeIsUpdated);
});
}
break;
case 'styleDeleted':

View File

@ -942,7 +942,7 @@ function createSectionsEditor(style) {
function replaceStyle(newStyle, codeIsUpdated) {
// FIXME: avoid recreating all editors?
reinit().then(() => {
style = newStyle;
Object.assign(style, newStyle);
updateHeader();
dirty.clear();
// Go from new style URL to edit style URL

View File

@ -216,7 +216,7 @@ function createSourceEditor(style) {
history.replaceState({}, '', `?id=${newStyle.id}`);
}
sessionStorage.justEditedStyleId = newStyle.id;
style = newStyle;
Object.assign(style, newStyle);
$('#preview-label').classList.remove('hidden');
updateMeta();
livePreview.show(Boolean(style.id));