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

View File

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

View File

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