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);
}
},
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 API */// msg.js
/* 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 createSection */// sections-editor-section.js
/* global editor */
@ -96,13 +96,7 @@ function SectionsEditor() {
if (!sameCode) {
await initSections(newStyle.sections, {replace: true});
}
Object.assign(style, 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}`);
}
editor.useSavedStyle(newStyle);
updateLivePreview();
},
@ -112,8 +106,8 @@ function SectionsEditor() {
return;
}
newStyle = await API.styles.editSave(newStyle);
sessionStore.justEditedStyleId = newStyle.id;
dirty.clear();
editor.useSavedStyle(newStyle);
},
scrollToEditor(cm) {

View File

@ -4,7 +4,7 @@
/* global MozDocMapper */// util.js
/* global MozSectionFinder */
/* global MozSectionWidget */
/* global RX_META debounce sessionStore */// toolbox.js
/* global RX_META debounce */// toolbox.js
/* global chromeSync */// storage-util.js
/* global cmFactory */
/* global editor */
@ -214,14 +214,14 @@ function SourceEditor() {
if (sameCode) {
savedGeneration = cm.changeGeneration();
dirty.clear('sourceGeneration');
updateEnvironment();
editor.useSavedStyle(newStyle);
dirty.clear('enabled');
updateLivePreview();
return;
}
if (await messageBoxProxy.confirm(t('styleUpdateDiscardChanges'))) {
updateEnvironment();
editor.useSavedStyle(newStyle);
if (!sameCode) {
const cursor = cm.getCursor();
cm.setValue(style.sourceCode);
@ -234,16 +234,6 @@ function SourceEditor() {
}
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) {