Add setStyleDirty, refactor replaceStyle
This commit is contained in:
parent
d93bf05f64
commit
c2687573b3
15
edit/edit.js
15
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'))) {
|
||||
return;
|
||||
}
|
||||
doReplace();
|
||||
|
||||
function doReplace() {
|
||||
if (!isUsercss(request.style)) {
|
||||
initWithSectionStyle(request);
|
||||
return;
|
||||
}
|
||||
if (codeIsUpdated) {
|
||||
editor.replaceStyle(request.style);
|
||||
} else {
|
||||
if (!codeIsUpdated) {
|
||||
editor.replaceMeta(request.style);
|
||||
}
|
||||
} else if (editor.isTouched() && !confirm(t('styleUpdateDiscardChanges'))) {
|
||||
editor.setStyleDirty(request.style);
|
||||
} else {
|
||||
editor.replaceStyle(request.style);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user