Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/common/viewLayout/viewLinesViewportData.ts
3294 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Range } from '../core/range.js';
7
import { Selection } from '../core/selection.js';
8
import { IPartialViewLinesViewportData, IViewModel, IViewWhitespaceViewportData, ViewLineRenderingData } from '../viewModel.js';
9
import { ViewModelDecoration } from '../viewModel/viewModelDecoration.js';
10
11
/**
12
* Contains all data needed to render at a specific viewport.
13
*/
14
export class ViewportData {
15
16
public readonly selections: Selection[];
17
18
/**
19
* The line number at which to start rendering (inclusive).
20
*/
21
public readonly startLineNumber: number;
22
23
/**
24
* The line number at which to end rendering (inclusive).
25
*/
26
public readonly endLineNumber: number;
27
28
/**
29
* relativeVerticalOffset[i] is the `top` position for line at `i` + `startLineNumber`.
30
*/
31
public readonly relativeVerticalOffset: number[];
32
33
/**
34
* The viewport as a range (startLineNumber,1) -> (endLineNumber,maxColumn(endLineNumber)).
35
*/
36
public readonly visibleRange: Range;
37
38
/**
39
* Value to be substracted from `scrollTop` (in order to vertical offset numbers < 1MM)
40
*/
41
public readonly bigNumbersDelta: number;
42
43
/**
44
* Positioning information about gaps whitespace.
45
*/
46
public readonly whitespaceViewportData: IViewWhitespaceViewportData[];
47
48
private readonly _model: IViewModel;
49
50
public readonly lineHeight: number;
51
52
constructor(
53
selections: Selection[],
54
partialData: IPartialViewLinesViewportData,
55
whitespaceViewportData: IViewWhitespaceViewportData[],
56
model: IViewModel
57
) {
58
this.selections = selections;
59
this.startLineNumber = partialData.startLineNumber | 0;
60
this.endLineNumber = partialData.endLineNumber | 0;
61
this.relativeVerticalOffset = partialData.relativeVerticalOffset;
62
this.bigNumbersDelta = partialData.bigNumbersDelta | 0;
63
this.lineHeight = partialData.lineHeight | 0;
64
this.whitespaceViewportData = whitespaceViewportData;
65
66
this._model = model;
67
68
this.visibleRange = new Range(
69
partialData.startLineNumber,
70
this._model.getLineMinColumn(partialData.startLineNumber),
71
partialData.endLineNumber,
72
this._model.getLineMaxColumn(partialData.endLineNumber)
73
);
74
}
75
76
public getViewLineRenderingData(lineNumber: number): ViewLineRenderingData {
77
return this._model.getViewportViewLineRenderingData(this.visibleRange, lineNumber);
78
}
79
80
public getDecorationsInViewport(): ViewModelDecoration[] {
81
return this._model.getDecorationsInViewport(this.visibleRange);
82
}
83
}
84
85