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