Add setStyleDirty, refactor replaceStyle

This commit is contained in:
eight 2017-11-09 14:07:06 +08:00
parent d93bf05f64
commit c2687573b3
2 changed files with 15 additions and 13 deletions

View File

@ -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);
}
}

View File

@ -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,