[html] editor.action.formatDocument removes <script> property. Fixes #36574

This commit is contained in:
Martin Aeschlimann 2017-11-15 12:47:36 +01:00
parent 5e7bb87cec
commit fc6640df6f
2 changed files with 5 additions and 1 deletions

View file

@ -253,7 +253,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
let start = currentTextDocument.offsetAt(range.start);
let end = currentTextDocument.offsetAt(range.end);
let lastLineRange = null;
if (range.end.character === 0 || isWhitespaceOnly(currentTextDocument.getText().substr(end - range.end.character, range.end.character))) {
if (range.end.line > range.start.line && (range.end.character === 0 || isWhitespaceOnly(currentTextDocument.getText().substr(end - range.end.character, range.end.character)))) {
end -= range.end.character;
lastLineRange = Range.create(Position.create(range.end.line, 0), range.end);
}

View file

@ -107,6 +107,10 @@ suite('HTML Embedded Formatting', () => {
assertFormat('<html><head>\n |<script>\nvar x=6;\n</script>\n|</head></html>', '<html><head>\n <script>\n var x = 6;\n </script>\n</head></html>');
});
test('bug 36574', function (): any {
assertFormat('<script src="/js/main.js"> </script>', '<script src="/js/main.js"> </script>');
});
});
function applyEdits(document: TextDocument, edits: TextEdit[]): string {