Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/browser/viewParts/margin/margin.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
import './margin.css';
7
import { FastDomNode, createFastDomNode } from '../../../../base/browser/fastDomNode.js';
8
import { ViewPart } from '../../view/viewPart.js';
9
import { RenderingContext, RestrictedRenderingContext } from '../../view/renderingContext.js';
10
import { ViewContext } from '../../../common/viewModel/viewContext.js';
11
import * as viewEvents from '../../../common/viewEvents.js';
12
import { EditorOption } from '../../../common/config/editorOptions.js';
13
14
/**
15
* Margin is a vertical strip located on the left of the editor's content area.
16
* It is used for various features such as line numbers, folding markers, and
17
* decorations that provide additional information about the lines of code.
18
*/
19
export class Margin extends ViewPart {
20
21
public static readonly CLASS_NAME = 'glyph-margin';
22
public static readonly OUTER_CLASS_NAME = 'margin';
23
24
private readonly _domNode: FastDomNode<HTMLElement>;
25
private _canUseLayerHinting: boolean;
26
private _contentLeft: number;
27
private _glyphMarginLeft: number;
28
private _glyphMarginWidth: number;
29
private _glyphMarginBackgroundDomNode: FastDomNode<HTMLElement>;
30
31
constructor(context: ViewContext) {
32
super(context);
33
const options = this._context.configuration.options;
34
const layoutInfo = options.get(EditorOption.layoutInfo);
35
36
this._canUseLayerHinting = !options.get(EditorOption.disableLayerHinting);
37
this._contentLeft = layoutInfo.contentLeft;
38
this._glyphMarginLeft = layoutInfo.glyphMarginLeft;
39
this._glyphMarginWidth = layoutInfo.glyphMarginWidth;
40
41
this._domNode = createFastDomNode(document.createElement('div'));
42
this._domNode.setClassName(Margin.OUTER_CLASS_NAME);
43
this._domNode.setPosition('absolute');
44
this._domNode.setAttribute('role', 'presentation');
45
this._domNode.setAttribute('aria-hidden', 'true');
46
47
this._glyphMarginBackgroundDomNode = createFastDomNode(document.createElement('div'));
48
this._glyphMarginBackgroundDomNode.setClassName(Margin.CLASS_NAME);
49
50
this._domNode.appendChild(this._glyphMarginBackgroundDomNode);
51
}
52
53
public override dispose(): void {
54
super.dispose();
55
}
56
57
public getDomNode(): FastDomNode<HTMLElement> {
58
return this._domNode;
59
}
60
61
// --- begin event handlers
62
63
public override onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean {
64
const options = this._context.configuration.options;
65
const layoutInfo = options.get(EditorOption.layoutInfo);
66
67
this._canUseLayerHinting = !options.get(EditorOption.disableLayerHinting);
68
this._contentLeft = layoutInfo.contentLeft;
69
this._glyphMarginLeft = layoutInfo.glyphMarginLeft;
70
this._glyphMarginWidth = layoutInfo.glyphMarginWidth;
71
72
return true;
73
}
74
public override onScrollChanged(e: viewEvents.ViewScrollChangedEvent): boolean {
75
return super.onScrollChanged(e) || e.scrollTopChanged;
76
}
77
78
// --- end event handlers
79
80
public prepareRender(ctx: RenderingContext): void {
81
// Nothing to read
82
}
83
84
public render(ctx: RestrictedRenderingContext): void {
85
this._domNode.setLayerHinting(this._canUseLayerHinting);
86
this._domNode.setContain('strict');
87
const adjustedScrollTop = ctx.scrollTop - ctx.bigNumbersDelta;
88
this._domNode.setTop(-adjustedScrollTop);
89
90
const height = Math.min(ctx.scrollHeight, 1000000);
91
this._domNode.setHeight(height);
92
this._domNode.setWidth(this._contentLeft);
93
94
this._glyphMarginBackgroundDomNode.setLeft(this._glyphMarginLeft);
95
this._glyphMarginBackgroundDomNode.setWidth(this._glyphMarginWidth);
96
this._glyphMarginBackgroundDomNode.setHeight(height);
97
}
98
}
99
100