Fix: add isWarm flag to decide if the editor can be reloaded
This commit is contained in:
parent
0a6de8edb8
commit
ce348d4f86
12
edit/edit.js
12
edit/edit.js
|
@ -1910,16 +1910,22 @@ chrome.runtime.onMessage.addListener(onRuntimeMessage);
|
|||
|
||||
function replaceStyle(request) {
|
||||
const codeIsUpdated = request.codeIsUpdated !== false;
|
||||
if (!isClean() && (!codeIsUpdated || !confirm(t('styleUpdateDiscardChanges')))) {
|
||||
if (codeIsUpdated && editor && editor.isWarm() && !confirm(t('styleUpdateDiscardChanges'))) {
|
||||
return;
|
||||
}
|
||||
doReplace();
|
||||
|
||||
function doReplace() {
|
||||
if (!isUsercss(request.style)) {
|
||||
initWithSectionStyle(request);
|
||||
return;
|
||||
}
|
||||
|
||||
editor.replaceStyle(request.style, codeIsUpdated);
|
||||
if (codeIsUpdated) {
|
||||
editor.replaceStyle(request.style);
|
||||
} else {
|
||||
editor.replaceMetas(request.style);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onRuntimeMessage(request) {
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
'use strict';
|
||||
|
||||
function createSourceEditor(style) {
|
||||
// a flag for isWorking()
|
||||
let hadBeenSaved = false;
|
||||
|
||||
// draw HTML
|
||||
$('#sections').innerHTML = '';
|
||||
$('#name').disabled = true;
|
||||
|
@ -614,6 +617,7 @@ ${section}
|
|||
cm.setCursor(cursor);
|
||||
}
|
||||
dirty.clear();
|
||||
hadBeenSaved = false;
|
||||
}
|
||||
|
||||
function toggleStyle() {
|
||||
|
@ -637,17 +641,33 @@ ${section}
|
|||
sourceCode: style.sourceCode
|
||||
}))
|
||||
.then(replaceStyle)
|
||||
.then(() => {
|
||||
hadBeenSaved = true;
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
alert(err);
|
||||
});
|
||||
}
|
||||
|
||||
function isWarm() {
|
||||
// indicate that the editor had been touched by the user
|
||||
return dirty.isDirty() || hadBeenSaved;
|
||||
}
|
||||
|
||||
function replaceMetas(newStyle) {
|
||||
style.enabled = newStyle.enabled;
|
||||
dirty.clear('enabled');
|
||||
updateMetas();
|
||||
}
|
||||
|
||||
return {
|
||||
replaceStyle,
|
||||
replaceMetas,
|
||||
save,
|
||||
toggleStyle,
|
||||
isDirty: dirty.isDirty,
|
||||
getStyle: () => style
|
||||
getStyle: () => style,
|
||||
isWarm
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user