From c2687573b333eac0e4ec070f1fb80b5ad7f5ce20 Mon Sep 17 00:00:00 2001 From: eight Date: Thu, 9 Nov 2017 14:07:06 +0800 Subject: [PATCH] Add setStyleDirty, refactor replaceStyle --- edit/edit.js | 21 ++++++++------------- edit/source-editor.js | 7 +++++++ 2 files changed, 15 insertions(+), 13 deletions(-) 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,