Path: blob/main/src/vs/editor/browser/viewParts/margin/margin.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import './margin.css';6import { FastDomNode, createFastDomNode } from '../../../../base/browser/fastDomNode.js';7import { ViewPart } from '../../view/viewPart.js';8import { RenderingContext, RestrictedRenderingContext } from '../../view/renderingContext.js';9import { ViewContext } from '../../../common/viewModel/viewContext.js';10import * as viewEvents from '../../../common/viewEvents.js';11import { EditorOption } from '../../../common/config/editorOptions.js';1213/**14* Margin is a vertical strip located on the left of the editor's content area.15* It is used for various features such as line numbers, folding markers, and16* decorations that provide additional information about the lines of code.17*/18export class Margin extends ViewPart {1920public static readonly CLASS_NAME = 'glyph-margin';21public static readonly OUTER_CLASS_NAME = 'margin';2223private readonly _domNode: FastDomNode<HTMLElement>;24private _canUseLayerHinting: boolean;25private _contentLeft: number;26private _glyphMarginLeft: number;27private _glyphMarginWidth: number;28private _glyphMarginBackgroundDomNode: FastDomNode<HTMLElement>;2930constructor(context: ViewContext) {31super(context);32const options = this._context.configuration.options;33const layoutInfo = options.get(EditorOption.layoutInfo);3435this._canUseLayerHinting = !options.get(EditorOption.disableLayerHinting);36this._contentLeft = layoutInfo.contentLeft;37this._glyphMarginLeft = layoutInfo.glyphMarginLeft;38this._glyphMarginWidth = layoutInfo.glyphMarginWidth;3940this._domNode = createFastDomNode(document.createElement('div'));41this._domNode.setClassName(Margin.OUTER_CLASS_NAME);42this._domNode.setPosition('absolute');43this._domNode.setAttribute('role', 'presentation');44this._domNode.setAttribute('aria-hidden', 'true');4546this._glyphMarginBackgroundDomNode = createFastDomNode(document.createElement('div'));47this._glyphMarginBackgroundDomNode.setClassName(Margin.CLASS_NAME);4849this._domNode.appendChild(this._glyphMarginBackgroundDomNode);50}5152public override dispose(): void {53super.dispose();54}5556public getDomNode(): FastDomNode<HTMLElement> {57return this._domNode;58}5960// --- begin event handlers6162public override onConfigurationChanged(e: viewEvents.ViewConfigurationChangedEvent): boolean {63const options = this._context.configuration.options;64const layoutInfo = options.get(EditorOption.layoutInfo);6566this._canUseLayerHinting = !options.get(EditorOption.disableLayerHinting);67this._contentLeft = layoutInfo.contentLeft;68this._glyphMarginLeft = layoutInfo.glyphMarginLeft;69this._glyphMarginWidth = layoutInfo.glyphMarginWidth;7071return true;72}73public override onScrollChanged(e: viewEvents.ViewScrollChangedEvent): boolean {74return super.onScrollChanged(e) || e.scrollTopChanged;75}7677// --- end event handlers7879public prepareRender(ctx: RenderingContext): void {80// Nothing to read81}8283public render(ctx: RestrictedRenderingContext): void {84this._domNode.setLayerHinting(this._canUseLayerHinting);85this._domNode.setContain('strict');86const adjustedScrollTop = ctx.scrollTop - ctx.bigNumbersDelta;87this._domNode.setTop(-adjustedScrollTop);8889const height = Math.min(ctx.scrollHeight, 1000000);90this._domNode.setHeight(height);91this._domNode.setWidth(this._contentLeft);9293this._glyphMarginBackgroundDomNode.setLeft(this._glyphMarginLeft);94this._glyphMarginBackgroundDomNode.setWidth(this._glyphMarginWidth);95this._glyphMarginBackgroundDomNode.setHeight(height);96}97}9899100