Skip to content

Commit 320f338

Browse files
authored
[html] Sytax Highlighting is way off with new line after event handler (microsoft#162319)
1 parent c4359c2 commit 320f338

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

extensions/html-language-features/server/src/modes/embeddedSupport.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ function getSuffix(c: EmbeddedRegion) {
196196
}
197197

198198
function substituteWithWhitespace(result: string, start: number, end: number, oldContent: string, before: string, after: string) {
199-
let accumulatedWS = 0;
200199
result += before;
201-
for (let i = start + before.length; i < end; i++) {
200+
let accumulatedWS = -before.length; // start with a negative value to account for the before string
201+
for (let i = start; i < end; i++) {
202202
const ch = oldContent[i];
203203
if (ch === '\n' || ch === '\r') {
204204
// only write new lines, skip the whitespace

extensions/html-language-features/server/src/test/embedded.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ suite('HTML Embedded Support', () => {
122122

123123
assertEmbeddedLanguageContent('<div onKeyUp="foo()" onkeydown="bar()"/>', 'javascript', ' foo(); bar(); ');
124124
assertEmbeddedLanguageContent('<div onKeyUp="return"/>', 'javascript', ' return; ');
125-
125+
assertEmbeddedLanguageContent('<div onKeyUp=return\n/><script>foo();</script>', 'javascript', ' return;\n foo(); ');
126126
});
127127

128128
});

0 commit comments

Comments
 (0)