Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/common/viewModel/glyphLanesModel.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 { GlyphMarginLane, IGlyphMarginLanesModel } from '../model.js';
8
9
10
const MAX_LANE = GlyphMarginLane.Right;
11
12
export class GlyphMarginLanesModel implements IGlyphMarginLanesModel {
13
private lanes: Uint8Array;
14
private persist = 0;
15
private _requiredLanes = 1; // always render at least one lane
16
17
constructor(maxLine: number) {
18
this.lanes = new Uint8Array(Math.ceil(((maxLine + 1) * MAX_LANE) / 8));
19
}
20
21
public reset(maxLine: number) {
22
const bytes = Math.ceil(((maxLine + 1) * MAX_LANE) / 8);
23
if (this.lanes.length < bytes) {
24
this.lanes = new Uint8Array(bytes);
25
} else {
26
this.lanes.fill(0);
27
}
28
this._requiredLanes = 1;
29
}
30
31
public get requiredLanes() {
32
return this._requiredLanes;
33
}
34
35
public push(lane: GlyphMarginLane, range: Range, persist?: boolean): void {
36
if (persist) {
37
this.persist |= (1 << (lane - 1));
38
}
39
for (let i = range.startLineNumber; i <= range.endLineNumber; i++) {
40
const bit = (MAX_LANE * i) + (lane - 1);
41
this.lanes[bit >>> 3] |= (1 << (bit % 8));
42
this._requiredLanes = Math.max(this._requiredLanes, this.countAtLine(i));
43
}
44
}
45
46
public getLanesAtLine(lineNumber: number): GlyphMarginLane[] {
47
const lanes: GlyphMarginLane[] = [];
48
let bit = MAX_LANE * lineNumber;
49
for (let i = 0; i < MAX_LANE; i++) {
50
if (this.persist & (1 << i) || this.lanes[bit >>> 3] & (1 << (bit % 8))) {
51
lanes.push(i + 1);
52
}
53
bit++;
54
}
55
56
return lanes.length ? lanes : [GlyphMarginLane.Center];
57
}
58
59
private countAtLine(lineNumber: number): number {
60
let bit = MAX_LANE * lineNumber;
61
let count = 0;
62
for (let i = 0; i < MAX_LANE; i++) {
63
if (this.persist & (1 << i) || this.lanes[bit >>> 3] & (1 << (bit % 8))) {
64
count++;
65
}
66
bit++;
67
}
68
return count;
69
}
70
}
71
72