add the site section to a custom usercss template for new styles

fixes #352
This commit is contained in:
tophf 2018-02-22 12:41:55 +03:00
parent d0d429bd8e
commit c5ef92cf9c
2 changed files with 9 additions and 3 deletions

View File

@ -1151,6 +1151,10 @@
"usercssReplaceTemplateConfirmation": {
"message": "Replace the default template for new Usercss styles with the current code?"
},
"usercssReplaceTemplateSectionBody": {
"message": "Insert code here...",
"description": "The code placeholder comment in a new style created by clicking 'Write style' in the popup"
},
"usercssConfigIncomplete": {
"message": "The style was updated or deleted after the configuration dialog was shown. These variables were not saved to avoid corrupting the style's metadata:"
},

View File

@ -98,7 +98,8 @@ function createSourceEditor(style) {
}
function setupNewStyle(style) {
style.sections[0].code = ' '.repeat(prefs.get('editor.tabSize')) + '/* Insert code here... */';
style.sections[0].code = ' '.repeat(prefs.get('editor.tabSize')) +
`/* ${t('usercssReplaceTemplateSectionBody')} */`;
let section = sectionsToMozFormat(style);
if (!section.includes('@-moz-document')) {
style.sections[0].domains = ['example.com'];
@ -115,13 +116,14 @@ function createSourceEditor(style) {
@description A new userstyle
@author Me
==/UserStyle== */
`.replace(/^\s+/gm, '') + '\n\n' + section;
`.replace(/^\s+/gm, '');
dirty.clear('sourceGeneration');
style.sourceCode = '';
chromeSync.getLZValue('usercssTemplate').then(code => {
style.sourceCode = code || DEFAULT_CODE;
code = code || DEFAULT_CODE;
style.sourceCode = code.replace(/\s+$/, '\n\n') + section;
cm.startOperation();
cm.setValue(style.sourceCode);
cm.clearHistory();