Skip to content

Commit

Permalink
Fixes #3462
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Feb 25, 2016
1 parent 78b557a commit 6f8016b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/vs/editor/common/viewLayout/viewLineParts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import * as strings from 'vs/base/common/strings';
import {Arrays} from 'vs/editor/common/core/arrays';
import {ILineToken, IRange, IViewLineTokens} from 'vs/editor/common/editorCommon';
import {Range} from 'vs/editor/common/core/range';

export interface ILineParts {

Expand All @@ -17,9 +18,17 @@ export interface ILineParts {
findIndexOfOffset(offset:number): number;
}

function cmpLineDecorations(a:ILineDecoration, b:ILineDecoration): number {
return Range.compareRangesUsingStarts(a.range, b.range);
}

export function createLineParts(lineNumber:number, lineContent:string, lineTokens:IViewLineTokens, rawLineDecorations:ILineDecoration[], renderWhitespace:boolean): ILineParts {
if (renderWhitespace) {
let oldLength = rawLineDecorations.length;
rawLineDecorations = insertWhitespace(lineNumber, lineContent, lineTokens.getFauxIndentLength(), rawLineDecorations);
if (rawLineDecorations.length !== oldLength) {
rawLineDecorations.sort(cmpLineDecorations);
}
}

if (rawLineDecorations.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/common/viewLayout/viewLineRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function renderLine(input:IRenderLineInput): IRenderLineOutput {

let partRendersWhitespace = false;
if (renderWhitespace) {
partRendersWhitespace = (/whitespace$/.test(part.type));
partRendersWhitespace = (/\bwhitespace\b/.test(part.type));
}

let toCharIndex = lineTextLength;
Expand Down
13 changes: 13 additions & 0 deletions src/vs/editor/test/common/viewLayout/viewLineParts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ suite('Editor ViewLayout - ViewLineParts', () => {
]);
});

test('issue #3462: no whitespace shown at the end of a decorated line', () => {

var result = LineDecorationsNormalizer.normalize(3, [
newDecoration(3, 15, 3, 21, 'trailing whitespace'),
newDecoration(3, 20, 3, 21, 'inline-folded'),
]);

assert.deepEqual(result, [
new DecorationSegment(14, 18, 'trailing whitespace'),
new DecorationSegment(19, 19, 'trailing whitespace inline-folded')
]);
});

test('ViewLineParts', () => {

assert.deepEqual(LineDecorationsNormalizer.normalize(1, [
Expand Down

0 comments on commit 6f8016b

Please sign in to comment.