diff --git a/edit/edit.js b/edit/edit.js index aa959128..19a94ac7 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -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(); + }, }); })(); diff --git a/edit/sections-editor.js b/edit/sections-editor.js index 214a6a73..854c801a 100644 --- a/edit/sections-editor.js +++ b/edit/sections-editor.js @@ -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) { diff --git a/edit/source-editor.js b/edit/source-editor.js index dc5e1388..5683c519 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -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) {