Skip to content

Commit

Permalink
Have InlineDecoration keep track of its type (#37401)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Nov 20, 2017
1 parent 7a81081 commit 08767f8
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 51 deletions.
4 changes: 2 additions & 2 deletions src/vs/editor/browser/widget/diffEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { ViewLineToken } from 'vs/editor/common/core/viewLineToken';
import { Configuration } from 'vs/editor/browser/config/configuration';
import { Position, IPosition } from 'vs/editor/common/core/position';
import { Selection, ISelection } from 'vs/editor/common/core/selection';
import { InlineDecoration } from 'vs/editor/common/viewModel/viewModel';
import { InlineDecoration, InlineDecorationType } from 'vs/editor/common/viewModel/viewModel';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { ColorId, MetadataConsts, FontStyle } from 'vs/editor/common/modes';
import Event, { Emitter } from 'vs/base/common/event';
Expand Down Expand Up @@ -1922,7 +1922,7 @@ class InlineViewZonesComputer extends ViewZonesComputer {
decorations.push(new InlineDecoration(
new Range(charChange.originalStartLineNumber, charChange.originalStartColumn, charChange.originalEndLineNumber, charChange.originalEndColumn),
'char-delete',
false
InlineDecorationType.Regular
));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/common/viewLayout/lineDecorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import { InlineDecoration } from 'vs/editor/common/viewModel/viewModel';
import { InlineDecoration, InlineDecorationType } from 'vs/editor/common/viewModel/viewModel';
import { Constants } from 'vs/editor/common/core/uint';
import * as strings from 'vs/base/common/strings';

Expand Down Expand Up @@ -75,7 +75,7 @@ export class LineDecoration {
continue;
}

result[resultLen++] = new LineDecoration(startColumn, endColumn, d.inlineClassName, d.insertsBeforeOrAfter);
result[resultLen++] = new LineDecoration(startColumn, endColumn, d.inlineClassName, d.type !== InlineDecorationType.Regular);
}

return result;
Expand Down
21 changes: 11 additions & 10 deletions src/vs/editor/common/viewModel/viewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,18 @@ export class ViewLineRenderingData {
}
}

export class InlineDecoration {
_inlineDecorationBrand: void;

readonly range: Range;
readonly inlineClassName: string;
readonly insertsBeforeOrAfter: boolean;
export const enum InlineDecorationType {
Regular = 0,
Before = 1,
After = 2
}

constructor(range: Range, inlineClassName: string, insertsBeforeOrAfter: boolean) {
this.range = range;
this.inlineClassName = inlineClassName;
this.insertsBeforeOrAfter = insertsBeforeOrAfter;
export class InlineDecoration {
constructor(
public readonly range: Range,
public readonly inlineClassName: string,
public readonly type: InlineDecorationType
) {
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/vs/editor/common/viewModel/viewModelDecorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import { Range } from 'vs/editor/common/core/range';
import { Position } from 'vs/editor/common/core/position';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { InlineDecoration, ViewModelDecoration, ICoordinatesConverter } from 'vs/editor/common/viewModel/viewModel';
import { InlineDecoration, ViewModelDecoration, ICoordinatesConverter, InlineDecorationType } from 'vs/editor/common/viewModel/viewModel';
import { IViewModelLinesCollection } from 'vs/editor/common/viewModel/splitLinesCollection';

export interface IDecorationsViewportData {
Expand Down Expand Up @@ -123,7 +123,7 @@ export class ViewModelDecorations implements IDisposable {
decorationsInViewport[decorationsInViewportLen++] = viewModelDecoration;

if (decorationOptions.inlineClassName) {
let inlineDecoration = new InlineDecoration(viewRange, decorationOptions.inlineClassName, false);
let inlineDecoration = new InlineDecoration(viewRange, decorationOptions.inlineClassName, InlineDecorationType.Regular);
let intersectedStartLineNumber = Math.max(startLineNumber, viewRange.startLineNumber);
let intersectedEndLineNumber = Math.min(endLineNumber, viewRange.endLineNumber);
for (let j = intersectedStartLineNumber; j <= intersectedEndLineNumber; j++) {
Expand All @@ -136,7 +136,7 @@ export class ViewModelDecorations implements IDisposable {
let inlineDecoration = new InlineDecoration(
new Range(viewRange.startLineNumber, viewRange.startColumn, viewRange.startLineNumber, viewRange.startColumn + 1),
decorationOptions.beforeContentClassName,
true
InlineDecorationType.Before
);
inlineDecorations[viewRange.startLineNumber - startLineNumber].push(inlineDecoration);
}
Expand All @@ -146,7 +146,7 @@ export class ViewModelDecorations implements IDisposable {
let inlineDecoration = new InlineDecoration(
new Range(viewRange.endLineNumber, viewRange.endColumn - 1, viewRange.endLineNumber, viewRange.endColumn),
decorationOptions.afterContentClassName,
true
InlineDecorationType.After
);
inlineDecorations[viewRange.endLineNumber - startLineNumber].push(inlineDecoration);
}
Expand Down
8 changes: 2 additions & 6 deletions src/vs/editor/test/common/viewLayout/lineDecorations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@
import * as assert from 'assert';
import { DecorationSegment, LineDecorationsNormalizer, LineDecoration } from 'vs/editor/common/viewLayout/lineDecorations';
import { Range } from 'vs/editor/common/core/range';
import { InlineDecoration } from 'vs/editor/common/viewModel/viewModel';
import { InlineDecoration, InlineDecorationType } from 'vs/editor/common/viewModel/viewModel';

suite('Editor ViewLayout - ViewLineParts', () => {

function newDecoration(startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number, inlineClassName: string): InlineDecoration {
return new InlineDecoration(new Range(startLineNumber, startColumn, endLineNumber, endColumn), inlineClassName, false);
}

test('Bug 9827:Overlapping inline decorations can cause wrong inline class to be applied', () => {

var result = LineDecorationsNormalizer.normalize('abcabcabcabcabcabcabcabcabcabc', [
Expand Down Expand Up @@ -45,7 +41,7 @@ suite('Editor ViewLayout - ViewLineParts', () => {
test('issue #3661: Link decoration bleeds to next line when wrapping', () => {

let result = LineDecoration.filter([
newDecoration(2, 12, 3, 30, 'detected-link')
new InlineDecoration(new Range(2, 12, 3, 30), 'detected-link', InlineDecorationType.Regular)
], 3, 12, 500);

assert.deepEqual(result, [
Expand Down
55 changes: 28 additions & 27 deletions src/vs/editor/test/common/viewModel/viewModelDecorations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as assert from 'assert';
import { Range } from 'vs/editor/common/core/range';
import { testViewModel } from 'vs/editor/test/common/viewModel/testViewModel';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { InlineDecorationType } from 'vs/editor/common/viewModel/viewModel';

suite('ViewModelDecorations', () => {
test('getDecorationsViewportData', () => {
Expand Down Expand Up @@ -105,107 +106,107 @@ suite('ViewModelDecorations', () => {
{
range: new Range(1, 2, 2, 1),
inlineClassName: 'i-dec2',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(1, 2, 2, 2),
inlineClassName: 'i-dec3',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(2, 1, 2, 2),
inlineClassName: 'a-dec3',
insertsBeforeOrAfter: true
type: InlineDecorationType.After
},
{
range: new Range(1, 2, 4, 1),
inlineClassName: 'i-dec4',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(1, 2, 5, 8),
inlineClassName: 'i-dec5',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(2, 1, 2, 1),
inlineClassName: 'i-dec6',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(2, 1, 2, 2),
inlineClassName: 'b-dec6',
insertsBeforeOrAfter: true
type: InlineDecorationType.Before
},
{
range: new Range(2, 1, 2, 3),
inlineClassName: 'i-dec7',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(2, 1, 2, 2),
inlineClassName: 'b-dec7',
insertsBeforeOrAfter: true
type: InlineDecorationType.Before
},
{
range: new Range(2, 2, 2, 3),
inlineClassName: 'a-dec7',
insertsBeforeOrAfter: true
type: InlineDecorationType.After
},
{
range: new Range(2, 1, 4, 1),
inlineClassName: 'i-dec8',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(2, 1, 2, 2),
inlineClassName: 'b-dec8',
insertsBeforeOrAfter: true
type: InlineDecorationType.Before
},
{
range: new Range(2, 1, 5, 8),
inlineClassName: 'i-dec9',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(2, 1, 2, 2),
inlineClassName: 'b-dec9',
insertsBeforeOrAfter: true
type: InlineDecorationType.Before
},
{
range: new Range(2, 3, 2, 5),
inlineClassName: 'i-dec10',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(2, 3, 2, 4),
inlineClassName: 'b-dec10',
insertsBeforeOrAfter: true
type: InlineDecorationType.Before
},
{
range: new Range(2, 4, 2, 5),
inlineClassName: 'a-dec10',
insertsBeforeOrAfter: true
type: InlineDecorationType.After
},
{
range: new Range(2, 3, 4, 1),
inlineClassName: 'i-dec11',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(2, 3, 2, 4),
inlineClassName: 'b-dec11',
insertsBeforeOrAfter: true
type: InlineDecorationType.Before
},
{
range: new Range(2, 3, 5, 8),
inlineClassName: 'i-dec12',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(2, 3, 2, 4),
inlineClassName: 'b-dec12',
insertsBeforeOrAfter: true
type: InlineDecorationType.Before
},
]);

Expand All @@ -219,32 +220,32 @@ suite('ViewModelDecorations', () => {
{
range: new Range(1, 2, 4, 1),
inlineClassName: 'i-dec4',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(1, 2, 5, 8),
inlineClassName: 'i-dec5',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(2, 1, 4, 1),
inlineClassName: 'i-dec8',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(2, 1, 5, 8),
inlineClassName: 'i-dec9',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(2, 3, 4, 1),
inlineClassName: 'i-dec11',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
{
range: new Range(2, 3, 5, 8),
inlineClassName: 'i-dec12',
insertsBeforeOrAfter: false
type: InlineDecorationType.Regular
},
]);
});
Expand Down

0 comments on commit 08767f8

Please sign in to comment.