Fixes #19673: Monokai Theme bad-highlighting in line wrap

This commit is contained in:
Alex Dima 2017-02-23 10:49:20 +01:00
parent a765e68c72
commit ec2ffab55f
3 changed files with 59 additions and 10 deletions

View file

@ -278,7 +278,7 @@ function resolveRenderLineInput(input: RenderLineInput): ResolvedRenderLineInput
len = lineContent.length;
}
let tokens = removeOverflowing(input.lineTokens, len);
let tokens = transformAndRemoveOverflowing(input.lineTokens, input.fauxIndentLength, len);
if (input.renderWhitespace === RenderWhitespace.All || input.renderWhitespace === RenderWhitespace.Boundary) {
tokens = _applyRenderWhitespace(lineContent, len, tokens, input.fauxIndentLength, input.tabSize, useMonospaceOptimizations, input.renderWhitespace === RenderWhitespace.Boundary);
}
@ -320,18 +320,29 @@ function resolveRenderLineInput(input: RenderLineInput): ResolvedRenderLineInput
* In the rendering phase, characters are always looped until token.endIndex.
* Ensure that all tokens end before `len` and the last one ends precisely at `len`.
*/
function removeOverflowing(tokens: ViewLineToken[], len: number): LinePart[] {
let result: LinePart[] = [];
function transformAndRemoveOverflowing(tokens: ViewLineToken[], fauxIndentLength: number, len: number): LinePart[] {
let result: LinePart[] = [], resultLen = 0;
// The faux indent part of the line should have no token type
if (fauxIndentLength > 0) {
result[resultLen++] = new LinePart(fauxIndentLength, '');
}
for (let tokenIndex = 0, tokensLen = tokens.length; tokenIndex < tokensLen; tokenIndex++) {
const token = tokens[tokenIndex];
const endIndex = token.endIndex;
if (endIndex <= fauxIndentLength) {
// The faux indent part of the line should have no token type
continue;
}
const type = token.getType();
if (endIndex >= len) {
result[tokenIndex] = new LinePart(len, type);
result[resultLen++] = new LinePart(len, type);
break;
}
result[tokenIndex] = new LinePart(endIndex, type);
result[resultLen++] = new LinePart(endIndex, type);
}
return result;
}
@ -388,10 +399,6 @@ function _applyRenderWhitespace(lineContent: string, len: number, tokens: LinePa
let tokenType = tokens[tokenIndex].type;
let tokenEndIndex = tokens[tokenIndex].endIndex;
if (fauxIndentLength > 0) {
result[resultLen++] = new LinePart(fauxIndentLength, '');
}
let firstNonWhitespaceIndex = strings.firstNonWhitespaceIndex(lineContent);
let lastNonWhitespaceIndex: number;
if (firstNonWhitespaceIndex === -1) {

View file

@ -77,7 +77,7 @@ suite('Editor ViewLayout - ViewLineParts', () => {
false
));
assert.deepEqual(actual.html.split(/></g), expected.split(/></g));
assert.deepEqual(actual.html, expected);
}
test('issue #18616: Inline decorations ending at the text length are no longer rendered', () => {

View file

@ -518,6 +518,48 @@ suite('viewLineRenderer.renderLine', () => {
assert.equal(actual.containsRTL, true);
});
test('issue #19673: Monokai Theme bad-highlighting in line wrap', () => {
let lineText = ' MongoCallback<string>): void {';
let lineParts = [
createPart(17, 1),
createPart(18, 2),
createPart(24, 3),
createPart(26, 4),
createPart(27, 5),
createPart(28, 6),
createPart(32, 7),
createPart(34, 8),
];
let expectedOutput = [
'<span class="">&nbsp;&nbsp;&nbsp;&nbsp;</span>',
'<span class="mtk1">MongoCallback</span>',
'<span class="mtk2">&lt;</span>',
'<span class="mtk3">string</span>',
'<span class="mtk4">&gt;)</span>',
'<span class="mtk5">:</span>',
'<span class="mtk6">&nbsp;</span>',
'<span class="mtk7">void</span>',
'<span class="mtk8">&nbsp;{</span>'
].join('');
let _actual = renderViewLine(new RenderLineInput(
true,
lineText,
false,
4,
lineParts,
[],
4,
10,
-1,
'none',
false
));
assert.equal(_actual.html, '<span>' + expectedOutput + '</span>');
});
function assertCharacterMapping(actual: CharacterMapping, expected: number[][]): void {
let charOffset = 0;
for (let partIndex = 0; partIndex < expected.length; partIndex++) {