add @-moz-document indent to beautifier

This commit is contained in:
tophf 2022-02-21 23:35:49 +03:00
parent d162928fb9
commit b75e2cb56b
3 changed files with 10 additions and 6 deletions

View File

@ -82,6 +82,7 @@ function createBeautifyUI(scope, options) {
$createOption('}', 'newline_between_rules'), $createOption('}', 'newline_between_rules'),
$createLabeledCheckbox('preserve_newlines', 'styleBeautifyPreserveNewlines'), $createLabeledCheckbox('preserve_newlines', 'styleBeautifyPreserveNewlines'),
$createLabeledCheckbox('indent_conditional', 'styleBeautifyIndentConditional'), $createLabeledCheckbox('indent_conditional', 'styleBeautifyIndentConditional'),
editor.isUsercss && $createLabeledCheckbox('indent_mozdoc', '', '... @-moz-document'),
]), ]),
$create('p.beautify-hint', [ $create('p.beautify-hint', [
$create('span', t('styleBeautifyHint') + '\u00A0'), $create('span', t('styleBeautifyHint') + '\u00A0'),
@ -148,7 +149,7 @@ function createBeautifyUI(scope, options) {
); );
} }
function $createLabeledCheckbox(optionName, i18nKey) { function $createLabeledCheckbox(optionName, i18nKey, text) {
return ( return (
$create('label', {style: 'display: block; clear: both;'}, [ $create('label', {style: 'display: block; clear: both;'}, [
$create('input', { $create('input', {
@ -158,7 +159,7 @@ function createBeautifyUI(scope, options) {
}), }),
$create('SVG:svg.svg-icon.checked', $create('SVG:svg.svg-icon.checked',
$create('SVG:use', {'xlink:href': '#svg-icon-checked'})), $create('SVG:use', {'xlink:href': '#svg-icon-checked'})),
t(i18nKey), i18nKey ? t(i18nKey) : text,
]) ])
); );
} }

View File

@ -84,6 +84,7 @@
preserve_newlines: true, preserve_newlines: true,
end_with_newline: false, end_with_newline: false,
indent_conditional: true, indent_conditional: true,
indent_mozdoc: true,
}, },
'editor.beautify.hotkey': '', 'editor.beautify.hotkey': '',
'editor.lintDelay': 300, // lint gutter marker update delay, ms 'editor.lintDelay': 300, // lint gutter marker update delay, ms

View File

@ -87,6 +87,7 @@
var lineBreak = /\r\n|[\n\r\u2028\u2029]/; var lineBreak = /\r\n|[\n\r\u2028\u2029]/;
var allLineBreaks = new RegExp(lineBreak.source, 'g'); var allLineBreaks = new RegExp(lineBreak.source, 'g');
var MOZ_DOC = "@-moz-document";
function css_beautify(source_text, options) { function css_beautify(source_text, options) {
options = options || {}; options = options || {};
@ -108,6 +109,7 @@
newline_between_rules = true, newline_between_rules = true,
space_around_combinator = true, space_around_combinator = true,
indent_conditional = true, indent_conditional = true,
indent_mozdoc = true,
newline_between_properties = true, newline_between_properties = true,
newline_before_open_brace = false, newline_before_open_brace = false,
newline_after_open_brace = true, newline_after_open_brace = true,
@ -303,7 +305,7 @@
newline_before_open_brace ? print.newLine() : print.singleSpace(); newline_before_open_brace ? print.newLine() : print.singleSpace();
output.push(ch); output.push(ch);
outputPosCol++; outputPosCol++;
if (!enteringConditionalGroup || indent_conditional) { if (!enteringConditionalGroup || (variableOrRule === MOZ_DOC ? indent_mozdoc : indent_conditional)) {
indent(); indent();
} }
if (!eatWhitespace(true)) { if (!eatWhitespace(true)) {
@ -439,7 +441,7 @@
nestedLevel += 1; nestedLevel += 1;
if (variableOrRule in css_beautify.CONDITIONAL_GROUP_RULE) { if (variableOrRule in css_beautify.CONDITIONAL_GROUP_RULE) {
enteringConditionalGroup = true; enteringConditionalGroup = true;
if (!indent_conditional) { if (variableOrRule === MOZ_DOC ? !indent_mozdoc : !indent_conditional) {
nestedLevel--; nestedLevel--;
} }
} }
@ -628,12 +630,12 @@
// also in CONDITIONAL_GROUP_RULE below // also in CONDITIONAL_GROUP_RULE below
"@media": true, "@media": true,
"@supports": true, "@supports": true,
"@-moz-document": true [MOZ_DOC]: true
}; };
css_beautify.CONDITIONAL_GROUP_RULE = { css_beautify.CONDITIONAL_GROUP_RULE = {
"@media": true, "@media": true,
"@supports": true, "@supports": true,
"@-moz-document": true [MOZ_DOC]: true
}; };
/*global define */ /*global define */