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) {
|
function replaceStyle(request) {
|
||||||
const codeIsUpdated = request.codeIsUpdated !== false;
|
const codeIsUpdated = request.codeIsUpdated !== false;
|
||||||
if (codeIsUpdated && editor && editor.isTouched() && !confirm(t('styleUpdateDiscardChanges'))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
doReplace();
|
|
||||||
|
|
||||||
function doReplace() {
|
|
||||||
if (!isUsercss(request.style)) {
|
if (!isUsercss(request.style)) {
|
||||||
initWithSectionStyle(request);
|
initWithSectionStyle(request);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (codeIsUpdated) {
|
if (!codeIsUpdated) {
|
||||||
editor.replaceStyle(request.style);
|
|
||||||
} else {
|
|
||||||
editor.replaceMeta(request.style);
|
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;
|
hadBeenSaved = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setStyleDirty(newStyle) {
|
||||||
|
dirty.clear();
|
||||||
|
dirty.modify('source', newStyle.sourceCode, style.sourceCode);
|
||||||
|
dirty.modify('enabled', newStyle.enabled, style.enabled);
|
||||||
|
}
|
||||||
|
|
||||||
function toggleStyle() {
|
function toggleStyle() {
|
||||||
const value = !style.enabled;
|
const value = !style.enabled;
|
||||||
dirty.modify('enabled', style.enabled, value);
|
dirty.modify('enabled', style.enabled, value);
|
||||||
|
@ -256,6 +262,7 @@ ${section}
|
||||||
return {
|
return {
|
||||||
replaceStyle,
|
replaceStyle,
|
||||||
replaceMeta,
|
replaceMeta,
|
||||||
|
setStyleDirty,
|
||||||
save,
|
save,
|
||||||
toggleStyle,
|
toggleStyle,
|
||||||
isDirty: dirty.isDirty,
|
isDirty: dirty.isDirty,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user