diff --git a/edit/edit.js b/edit/edit.js index 6d4e4dae..93925b66 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -1894,21 +1894,16 @@ chrome.runtime.onMessage.addListener(onRuntimeMessage); function replaceStyle(request) { const codeIsUpdated = request.codeIsUpdated !== false; - if (codeIsUpdated && editor && editor.isTouched() && !confirm(t('styleUpdateDiscardChanges'))) { + if (!isUsercss(request.style)) { + initWithSectionStyle(request); return; } - doReplace(); - - function doReplace() { - if (!isUsercss(request.style)) { - initWithSectionStyle(request); - return; - } - if (codeIsUpdated) { - editor.replaceStyle(request.style); - } else { - editor.replaceMeta(request.style); - } + if (!codeIsUpdated) { + editor.replaceMeta(request.style); + } else if (editor.isTouched() && !confirm(t('styleUpdateDiscardChanges'))) { + editor.setStyleDirty(request.style); + } else { + editor.replaceStyle(request.style); } } diff --git a/edit/source-editor.js b/edit/source-editor.js index 5aa37dbb..970af308 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -212,6 +212,12 @@ ${section} hadBeenSaved = false; } + function setStyleDirty(newStyle) { + dirty.clear(); + dirty.modify('source', newStyle.sourceCode, style.sourceCode); + dirty.modify('enabled', newStyle.enabled, style.enabled); + } + function toggleStyle() { const value = !style.enabled; dirty.modify('enabled', style.enabled, value); @@ -256,6 +262,7 @@ ${section} return { replaceStyle, replaceMeta, + setStyleDirty, save, toggleStyle, isDirty: dirty.isDirty,