mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
Fixes #19673: Monokai Theme bad-highlighting in line wrap
This commit is contained in:
parent
a765e68c72
commit
ec2ffab55f
|
@ -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) {
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
|
@ -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=""> </span>',
|
||||
'<span class="mtk1">MongoCallback</span>',
|
||||
'<span class="mtk2"><</span>',
|
||||
'<span class="mtk3">string</span>',
|
||||
'<span class="mtk4">>)</span>',
|
||||
'<span class="mtk5">:</span>',
|
||||
'<span class="mtk6"> </span>',
|
||||
'<span class="mtk7">void</span>',
|
||||
'<span class="mtk8"> {</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++) {
|
||||
|
|
Loading…
Reference in a new issue