fill an empty @name with the default placeholder

fixes #462
This commit is contained in:
tophf 2018-08-06 13:35:33 +03:00
parent e27636b93d
commit 5f623f2f0e

View File

@ -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();