diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 39f194f3..fee1ee22 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -250,6 +250,13 @@ "message": "Copy to clipboard", "description": "Tooltip for elements which can be copied" }, + "customNameHint": { + "message": "Enter a custom name here to rename the style in UI without breaking its updates" + }, + "customNameResetHint": { + "message": "Stop using customized name, switch to the style's own name", + "description": "Tooltip of 'x' button shown in editor when changing the name input of a) styles updated from a URL i.e. not locally created, b) UserCSS styles" + }, "dateInstalled": { "message": "Date installed", "description": "Option text for the user to sort the style by install date" diff --git a/background/search-db.js b/background/search-db.js index 75318304..21ef0572 100644 --- a/background/search-db.js +++ b/background/search-db.js @@ -57,7 +57,7 @@ continue; } for (const part in PARTS) { - const text = style[part]; + const text = part === 'name' ? style.customName || style.name : style[part]; if (text && PARTS[part](text, rx, words, icase)) { results.push(id); break; diff --git a/background/style-manager.js b/background/style-manager.js index 4ae2a5c2..44c215e0 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -61,6 +61,8 @@ const styleManager = (() => { username: '' }; + const DELETE_IF_NULL = ['id', 'customName']; + handleLivePreviewConnections(); return Object.assign({ @@ -387,8 +389,10 @@ const styleManager = (() => { if (!style.name) { throw new Error('style name is empty'); } - if (style.id == null) { - delete style.id; + for (const key of DELETE_IF_NULL) { + if (style[key] == null) { + delete style[key]; + } } if (!style._id) { style._id = uuidv4(); @@ -569,6 +573,16 @@ const styleManager = (() => { touched = true; } } + // upgrade the old way of customizing local names + const {originalName} = style; + if (originalName) { + touched = true; + if (originalName !== style.name) { + style.customName = style.name; + style.name = originalName; + } + delete style.originalName; + } return touched; } } diff --git a/background/update.js b/background/update.js index 2a0e02a7..33c2022c 100644 --- a/background/update.js +++ b/background/update.js @@ -116,7 +116,7 @@ } function reportSuccess(saved) { - log(STATES.UPDATED + ` #${style.id} ${style.name}`); + log(STATES.UPDATED + ` #${style.id} ${style.customName || style.name}`); const info = {updated: true, style: saved}; if (port) port.postMessage(info); return info; @@ -139,7 +139,7 @@ if (typeof error === 'object' && error.message) { error = error.message; } - log(STATES.SKIPPED + ` (${error}) #${style.id} ${style.name}`); + log(STATES.SKIPPED + ` (${error}) #${style.id} ${style.customName || style.name}`); const info = {error, STATES, style: getStyleWithNoCode(style)}; if (port) port.postMessage(info); return info; @@ -207,13 +207,6 @@ // keep current state delete json.enabled; - // keep local name customizations - if (style.originalName !== style.name && style.name !== json.name) { - delete json.name; - } else { - json.originalName = json.name; - } - const newStyle = Object.assign({}, style, json); if (styleSectionsEqual(json, style, {checkSource: true})) { // update digest even if save === false as there might be just a space added etc. diff --git a/edit.html b/edit.html index b87396fe..5d7d0c00 100644 --- a/edit.html +++ b/edit.html @@ -18,6 +18,22 @@ } + + + + + + + + + + + + + + + + @@ -63,44 +79,27 @@ - - - - - - - - - - - - - - - + - + - + + - - - - - + @@ -109,8 +108,6 @@ - -