Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/browser/viewParts/viewLines/domReadingContext.ts
3296 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
export class DomReadingContext {
7
8
private _didDomLayout: boolean = false;
9
private _clientRectDeltaLeft: number = 0;
10
private _clientRectScale: number = 1;
11
private _clientRectRead: boolean = false;
12
13
public get didDomLayout(): boolean {
14
return this._didDomLayout;
15
}
16
17
private readClientRect(): void {
18
if (!this._clientRectRead) {
19
this._clientRectRead = true;
20
const rect = this._domNode.getBoundingClientRect();
21
this.markDidDomLayout();
22
this._clientRectDeltaLeft = rect.left;
23
this._clientRectScale = rect.width / this._domNode.offsetWidth;
24
}
25
}
26
27
public get clientRectDeltaLeft(): number {
28
if (!this._clientRectRead) {
29
this.readClientRect();
30
}
31
return this._clientRectDeltaLeft;
32
}
33
34
public get clientRectScale(): number {
35
if (!this._clientRectRead) {
36
this.readClientRect();
37
}
38
return this._clientRectScale;
39
}
40
41
constructor(
42
private readonly _domNode: HTMLElement,
43
public readonly endNode: HTMLElement
44
) {
45
}
46
47
public markDidDomLayout(): void {
48
this._didDomLayout = true;
49
}
50
}
51
52