Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/browser/view/viewPart.ts
5221 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 { FastDomNode } from '../../../base/browser/fastDomNode.js';
7
import { RenderingContext, RestrictedRenderingContext } from './renderingContext.js';
8
import { ViewContext } from '../../common/viewModel/viewContext.js';
9
import { ViewEventHandler } from '../../common/viewEventHandler.js';
10
import { ViewportData } from '../../common/viewLayout/viewLinesViewportData.js';
11
12
export abstract class ViewPart extends ViewEventHandler {
13
14
_context: ViewContext;
15
16
constructor(context: ViewContext) {
17
super();
18
this._context = context;
19
this._context.addEventHandler(this);
20
}
21
22
public override dispose(): void {
23
this._context.removeEventHandler(this);
24
super.dispose();
25
}
26
27
public onBeforeRender(viewportData: ViewportData): void {
28
}
29
30
public abstract prepareRender(ctx: RenderingContext): void;
31
public abstract render(ctx: RestrictedRenderingContext): void;
32
}
33
34
export const enum PartFingerprint {
35
None,
36
ContentWidgets,
37
OverflowingContentWidgets,
38
OverflowGuard,
39
OverlayWidgets,
40
OverflowingOverlayWidgets,
41
ScrollableElement,
42
TextArea,
43
ViewLines,
44
Minimap,
45
ViewLinesGpu
46
}
47
48
export class PartFingerprints {
49
50
public static write(target: Element | FastDomNode<HTMLElement>, partId: PartFingerprint) {
51
target.setAttribute('data-mprt', String(partId));
52
}
53
54
public static read(target: Element): PartFingerprint {
55
const r = target.getAttribute('data-mprt');
56
if (r === null) {
57
return PartFingerprint.None;
58
}
59
return parseInt(r, 10);
60
}
61
62
public static collect(child: Element | null, stopAt: Element): Uint8Array {
63
const result: PartFingerprint[] = [];
64
let resultLen = 0;
65
66
while (child && child !== child.ownerDocument.body) {
67
if (child === stopAt) {
68
break;
69
}
70
if (child.nodeType === child.ELEMENT_NODE) {
71
result[resultLen++] = this.read(child);
72
}
73
child = child.parentElement;
74
}
75
76
const r = new Uint8Array(resultLen);
77
for (let i = 0; i < resultLen; i++) {
78
r[i] = result[resultLen - i - 1];
79
}
80
return r;
81
}
82
}
83
84