Skip to content

Commit

Permalink
Merge pull request #38 from AHKol/fix-58693
Browse files Browse the repository at this point in the history
Fix 58693
  • Loading branch information
aeschli authored Oct 29, 2018
2 parents 5c334c1 + 2db1454 commit 6ab27b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
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);
});

});

0 comments on commit 6ab27b1

Please sign in to comment.