mirror of
https://github.com/Microsoft/vscode
synced 2024-10-06 03:17:00 +00:00
[html] files.insertFinalNewline affects embedded styles (#179118)
This commit is contained in:
parent
f481836a89
commit
92b87b0fd5
|
@ -54,7 +54,11 @@ export async function format(languageModes: LanguageModes, document: TextDocumen
|
|||
// perform a html format and apply changes to a new document
|
||||
const htmlMode = languageModes.getMode('html')!;
|
||||
const htmlEdits = await htmlMode.format!(document, formatRange, formattingOptions, settings);
|
||||
const htmlFormattedContent = TextDocument.applyEdits(document, htmlEdits);
|
||||
let htmlFormattedContent = TextDocument.applyEdits(document, htmlEdits);
|
||||
if (formattingOptions.insertFinalNewline && endOffset === content.length && !htmlFormattedContent.endsWith('\n')) {
|
||||
htmlFormattedContent = htmlFormattedContent + '\n';
|
||||
htmlEdits.push(TextEdit.insert(endPos, '\n'));
|
||||
}
|
||||
const newDocument = TextDocument.create(document.uri + '.tmp', document.languageId, document.version, htmlFormattedContent);
|
||||
try {
|
||||
// run embedded formatters on html formatted content: - formatters see correct initial indent
|
||||
|
|
|
@ -49,9 +49,6 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
|
|||
} else {
|
||||
formatSettings.contentUnformatted = 'script';
|
||||
}
|
||||
if (formatParams.insertFinalNewline) {
|
||||
formatSettings.endWithNewline = true;
|
||||
}
|
||||
merge(formatParams, formatSettings);
|
||||
return htmlLanguageService.format(document, range, formatSettings);
|
||||
},
|
||||
|
|
|
@ -85,11 +85,12 @@ suite('HTML Embedded Formatting', () => {
|
|||
});
|
||||
|
||||
test('EndWithNewline', async () => {
|
||||
const options : FormattingOptions = FormattingOptions.create(2, true);
|
||||
const options: FormattingOptions = FormattingOptions.create(2, true);
|
||||
options.insertFinalNewline = true;
|
||||
|
||||
|
||||
await assertFormat('<html><body><p>Hello</p></body></html>', '<html>\n\n<body>\n <p>Hello</p>\n</body>\n\n</html>\n', {}, options);
|
||||
await assertFormat('<html>|<body><p>Hello</p></body>|</html>', '<html><body>\n <p>Hello</p>\n</body></html>', {}, options);
|
||||
await assertFormat('<html>|<body><p>Hello</p></body></html>|', '<html><body>\n <p>Hello</p>\n</body>\n\n</html>\n', {}, options);
|
||||
await assertFormat('<html><head><script>\nvar x=1;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 1;\n </script>\n</head>\n\n</html>\n', {}, options);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue