Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 58693 #38

Merged
merged 10 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/services/htmlFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ export function format(document: TextDocument, range: Range | undefined, options
}
range = Range.create(document.positionAt(startOffset), document.positionAt(endOffset));

//Do not modify if substring in inside an element
let firstHalf = value.substring(0, startOffset);
let secondHalf = value.substring(endOffset, value.length);
if(new RegExp(/.*[<][^>]*$/).test(firstHalf) && new RegExp(/^[^<]*[>].*/).test(secondHalf) ){
//return without modification
value = value.substring(startOffset, endOffset);
return [{
range: range,
newText: value
}];
}

includesEnd = endOffset === value.length;
value = value.substring(startOffset, endOffset);

Expand Down
15 changes: 14 additions & 1 deletion src/test/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,17 @@ suite('JSON Formatter', () => {

format(content, expected);
});
});

test('bug 58693', () => {
var content = [
'<a class="btn| btn-link|"></a>'
].join('\n');

var expected = [
'<a class="btn btn-link"></a>'
].join('\n');

format(content, expected);
});

});