From 59f3f23b55163752b4d5300563ad544019536c68 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sat, 12 Jun 2021 17:45:16 +0200 Subject: [PATCH] Ensure correct style is pre-filled --- background/style-manager.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/background/style-manager.js b/background/style-manager.js index 53d22a1f..f7a49869 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -367,15 +367,17 @@ const styleMan = (() => { case 'publish': if (!style._usw || !style._usw.token) { - style._linking = true; - await saveStyle(style); - const data = id2data(style.id); - if (!data) { - storeInMap(style); - } else { - data.style = style; + // Ensures just the style does have the _linking property as `true`. + for (const {style: someStyle} of dataMap.values()) { + if (someStyle._id === style._id) { + someStyle._linking = true; + someStyle.sourceCode = style.sourceCode; + } else { + delete someStyle._linking; + delete someStyle.sourceCode; + } + handleSave(await saveStyle(someStyle), null, null, false); } - style._usw = { token: await tokenMan.getToken('userstylesworld', true, style), }; @@ -477,7 +479,7 @@ const styleMan = (() => { return style; } - function handleSave(style, reason, codeIsUpdated) { + function handleSave(style, reason, codeIsUpdated, broadcast = true) { const data = id2data(style.id); const method = data ? 'styleUpdated' : 'styleAdded'; if (!data) { @@ -485,7 +487,7 @@ const styleMan = (() => { } else { data.style = style; } - broadcastStyleUpdated(style, reason, method, codeIsUpdated); + if (broadcast) broadcastStyleUpdated(style, reason, method, codeIsUpdated); return style; }