Fix: make codeIsUpdated flag work properly

This commit is contained in:
eight 2017-09-12 19:57:43 +08:00
parent e7eb38bba9
commit 4b2f7a1a46
2 changed files with 16 additions and 7 deletions

View File

@ -1365,17 +1365,21 @@ function setStyleMeta(style) {
$('#url').href = style.url || '';
}
function initWithStyle({style}) {
// FIXME: what does codeIsUpdated do?
function initWithStyle(request) {
if (!style.usercss) {
initWithSectionStyle({style});
initWithSectionStyle(request);
return;
}
if (editor) {
editor.replaceStyle(style);
if (!editor) {
editor = createSourceEditor(request.style);
return;
}
if (request.codeIsUpdated === false) {
editor.updateStyleMeta(request.style);
} else {
editor = createSourceEditor(style);
editor.replaceStyle(request.style);
}
}

View File

@ -95,6 +95,11 @@ function createSourceEditor(style) {
dirty.clear();
}
function updateStyleMeta(_style) {
dirty.modify('enabled', style.enabled, _style.enabled);
style.enabled = _style.enabled;
}
function toggleStyle() {
const value = !style.enabled;
dirty.modify('enabled', style.enabled, value);
@ -132,5 +137,5 @@ function createSourceEditor(style) {
});
}
return {replaceStyle, save, toggleStyle};
return {replaceStyle, save, toggleStyle, updateStyleMeta};
}