From c5ef92cf9cee53b459d65451309de2d833521364 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 22 Feb 2018 12:41:55 +0300 Subject: [PATCH] add the site section to a custom usercss template for new styles fixes #352 --- _locales/en/messages.json | 4 ++++ edit/source-editor.js | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 1ad11c06..1c95a62c 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -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:" }, diff --git a/edit/source-editor.js b/edit/source-editor.js index 324a056b..1e53283a 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -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();