From 6f8016bbec0f6a3ccc82873594d975ae66f985f2 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 25 Feb 2016 22:20:43 +0100 Subject: [PATCH] Fixes #3462 --- src/vs/editor/common/viewLayout/viewLineParts.ts | 9 +++++++++ src/vs/editor/common/viewLayout/viewLineRenderer.ts | 2 +- .../test/common/viewLayout/viewLineParts.test.ts | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/vs/editor/common/viewLayout/viewLineParts.ts b/src/vs/editor/common/viewLayout/viewLineParts.ts index 5ce8d92dc9ba7..1ff7b408f2a67 100644 --- a/src/vs/editor/common/viewLayout/viewLineParts.ts +++ b/src/vs/editor/common/viewLayout/viewLineParts.ts @@ -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 { @@ -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) { diff --git a/src/vs/editor/common/viewLayout/viewLineRenderer.ts b/src/vs/editor/common/viewLayout/viewLineRenderer.ts index 1b98b10676c45..b8973b0767ede 100644 --- a/src/vs/editor/common/viewLayout/viewLineRenderer.ts +++ b/src/vs/editor/common/viewLayout/viewLineRenderer.ts @@ -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; diff --git a/src/vs/editor/test/common/viewLayout/viewLineParts.test.ts b/src/vs/editor/test/common/viewLayout/viewLineParts.test.ts index bcb33eb721780..175bf1105284d 100644 --- a/src/vs/editor/test/common/viewLayout/viewLineParts.test.ts +++ b/src/vs/editor/test/common/viewLayout/viewLineParts.test.ts @@ -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, [