From 5f623f2f0e7e005e159536095741c08de451d1a1 Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 6 Aug 2018 13:35:33 +0300 Subject: [PATCH] fill an empty @name with the default placeholder fixes #462 --- edit/source-editor.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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();