From be633bf90344d5c6b488c75a31f1190b95c7cb1a Mon Sep 17 00:00:00 2001 From: tophf Date: Wed, 29 Nov 2017 13:34:00 +0300 Subject: [PATCH] usercss: update URL and sessionStorage on replacing the style --- edit/source-editor.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/edit/source-editor.js b/edit/source-editor.js index 4f6ee180..f2f07859 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -169,21 +169,16 @@ function createSourceEditor(style) { dirty.clear('sourceGeneration'); } if (codeIsUpdated === false || sameCode) { - // copy changed meta anyway - style = deepCopy(newStyle); + updateEnvironment(); dirty.clear('enabled'); - updateMeta(); return; } + Promise.resolve(messageBox.confirm(t('styleUpdateDiscardChanges'))).then(ok => { if (!ok) { return; } - if (!style.id && newStyle.id) { - history.replaceState({}, '', `?id=${newStyle.id}`); - } - style = deepCopy(newStyle); - updateMeta(); + updateEnvironment(); if (!sameCode) { const cursor = cm.getCursor(); cm.setValue(style.sourceCode); @@ -192,6 +187,15 @@ function createSourceEditor(style) { } dirty.clear(); }); + + function updateEnvironment() { + if (style.id !== newStyle.id) { + history.replaceState({}, '', `?id=${newStyle.id}`); + } + sessionStorage.justEditedStyleId = newStyle.id; + style = deepCopy(newStyle); + updateMeta(); + } } function toggleStyle() {