deduplicate editor.useSavedStyle
...and call it when saving in sectioned editor (regressed in ba9d904c)
			
			
This commit is contained in:
		
							parent
							
								
									6e4fc3236e
								
							
						
					
					
						commit
						68dc584749
					
				
							
								
								
									
										10
									
								
								edit/edit.js
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								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(); | ||||
|     }, | ||||
|   }); | ||||
| })(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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) { | ||||
|  |  | |||
|  | @ -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) { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user