deduplicate editor.useSavedStyle

...and call it when saving in sectioned editor (regressed in ba9d904c)
This commit is contained in:
tophf 2022-01-10 21:29:07 +03:00
parent 6e4fc3236e
commit 68dc584749
3 changed files with 16 additions and 22 deletions

View File

@ -266,6 +266,16 @@ window.on('beforeunload', e => {
el.classList.add(cls); el.classList.add(cls);
} }
}, },
useSavedStyle(newStyle) {
if (style.id !== newStyle.id) {
history.replaceState({}, '', `?id=${newStyle.id}`);
}
sessionStore.justEditedStyleId = newStyle.id;
Object.assign(style, newStyle);
editor.updateClass();
editor.updateMeta();
},
}); });
})(); })();

View File

@ -1,7 +1,7 @@
/* global $ $$ $create $remove messageBoxProxy */// dom.js /* global $ $$ $create $remove messageBoxProxy */// dom.js
/* global API */// msg.js /* global API */// msg.js
/* global CodeMirror */ /* global CodeMirror */
/* global FIREFOX RX_META debounce ignoreChromeError sessionStore */// toolbox.js /* global FIREFOX RX_META debounce ignoreChromeError */// toolbox.js
/* global MozDocMapper clipString helpPopup rerouteHotkeys showCodeMirrorPopup */// util.js /* global MozDocMapper clipString helpPopup rerouteHotkeys showCodeMirrorPopup */// util.js
/* global createSection */// sections-editor-section.js /* global createSection */// sections-editor-section.js
/* global editor */ /* global editor */
@ -96,13 +96,7 @@ function SectionsEditor() {
if (!sameCode) { if (!sameCode) {
await initSections(newStyle.sections, {replace: true}); await initSections(newStyle.sections, {replace: true});
} }
Object.assign(style, newStyle); editor.useSavedStyle(newStyle);
editor.updateClass();
updateMeta();
// Go from new style URL to edit style URL
if (style.id && !/[&?]id=/.test(location.search)) {
history.replaceState({}, document.title, `${location.pathname}?id=${style.id}`);
}
updateLivePreview(); updateLivePreview();
}, },
@ -112,8 +106,8 @@ function SectionsEditor() {
return; return;
} }
newStyle = await API.styles.editSave(newStyle); newStyle = await API.styles.editSave(newStyle);
sessionStore.justEditedStyleId = newStyle.id;
dirty.clear(); dirty.clear();
editor.useSavedStyle(newStyle);
}, },
scrollToEditor(cm) { scrollToEditor(cm) {

View File

@ -4,7 +4,7 @@
/* global MozDocMapper */// util.js /* global MozDocMapper */// util.js
/* global MozSectionFinder */ /* global MozSectionFinder */
/* global MozSectionWidget */ /* global MozSectionWidget */
/* global RX_META debounce sessionStore */// toolbox.js /* global RX_META debounce */// toolbox.js
/* global chromeSync */// storage-util.js /* global chromeSync */// storage-util.js
/* global cmFactory */ /* global cmFactory */
/* global editor */ /* global editor */
@ -214,14 +214,14 @@ function SourceEditor() {
if (sameCode) { if (sameCode) {
savedGeneration = cm.changeGeneration(); savedGeneration = cm.changeGeneration();
dirty.clear('sourceGeneration'); dirty.clear('sourceGeneration');
updateEnvironment(); editor.useSavedStyle(newStyle);
dirty.clear('enabled'); dirty.clear('enabled');
updateLivePreview(); updateLivePreview();
return; return;
} }
if (await messageBoxProxy.confirm(t('styleUpdateDiscardChanges'))) { if (await messageBoxProxy.confirm(t('styleUpdateDiscardChanges'))) {
updateEnvironment(); editor.useSavedStyle(newStyle);
if (!sameCode) { if (!sameCode) {
const cursor = cm.getCursor(); const cursor = cm.getCursor();
cm.setValue(style.sourceCode); cm.setValue(style.sourceCode);
@ -234,16 +234,6 @@ function SourceEditor() {
} }
dirty.clear(); dirty.clear();
} }
function updateEnvironment() {
if (style.id !== newStyle.id) {
history.replaceState({}, '', `?id=${newStyle.id}`);
}
sessionStore.justEditedStyleId = newStyle.id;
Object.assign(style, newStyle);
editor.updateClass();
updateMeta();
}
} }
async function saveTemplate(code) { async function saveTemplate(code) {