diff --git a/edit/source-editor.js b/edit/source-editor.js index 53f8d510..27ecde42 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -110,12 +110,9 @@ function createSourceEditor(style) { } const DEFAULT_CODE = ` /* ==UserStyle== - @name ${ - style.name || - t('usercssReplaceTemplateName') + ' - ' + new Date().toLocaleString() - } + @name ${''/* a trick to preserve the trailing spaces */} @namespace github.com/openstyles/stylus - @version 0.1.0 + @version 1.0.0 @description A new userstyle @author Me ==/UserStyle== */ @@ -126,6 +123,10 @@ function createSourceEditor(style) { chromeSync.getLZValue('usercssTemplate').then(code => { code = code || DEFAULT_CODE; + code = code.replace(/@name(\s*)(?=[\r\n])/, (str, space) => + `${str}${space ? '' : ' '}${ + style.name || + t('usercssReplaceTemplateName') + ' - ' + new Date().toLocaleString()}`); // strip the last dummy section if any, add an empty line followed by the section style.sourceCode = code.replace(/@-moz-document[^{]*\{[^}]*\}\s*$|\s+$/g, '') + '\n\n' + section; cm.startOperation();