usercss: update URL and sessionStorage on replacing the style

This commit is contained in:
tophf 2017-11-29 13:34:00 +03:00
parent 260cbddae0
commit be633bf903

View File

@ -169,21 +169,16 @@ function createSourceEditor(style) {
dirty.clear('sourceGeneration'); dirty.clear('sourceGeneration');
} }
if (codeIsUpdated === false || sameCode) { if (codeIsUpdated === false || sameCode) {
// copy changed meta anyway updateEnvironment();
style = deepCopy(newStyle);
dirty.clear('enabled'); dirty.clear('enabled');
updateMeta();
return; return;
} }
Promise.resolve(messageBox.confirm(t('styleUpdateDiscardChanges'))).then(ok => { Promise.resolve(messageBox.confirm(t('styleUpdateDiscardChanges'))).then(ok => {
if (!ok) { if (!ok) {
return; return;
} }
if (!style.id && newStyle.id) { updateEnvironment();
history.replaceState({}, '', `?id=${newStyle.id}`);
}
style = deepCopy(newStyle);
updateMeta();
if (!sameCode) { if (!sameCode) {
const cursor = cm.getCursor(); const cursor = cm.getCursor();
cm.setValue(style.sourceCode); cm.setValue(style.sourceCode);
@ -192,6 +187,15 @@ function createSourceEditor(style) {
} }
dirty.clear(); dirty.clear();
}); });
function updateEnvironment() {
if (style.id !== newStyle.id) {
history.replaceState({}, '', `?id=${newStyle.id}`);
}
sessionStorage.justEditedStyleId = newStyle.id;
style = deepCopy(newStyle);
updateMeta();
}
} }
function toggleStyle() { function toggleStyle() {