Path: blob/main/src/vs/editor/common/viewModel/glyphLanesModel.ts
3294 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 { Range } from '../core/range.js';6import { GlyphMarginLane, IGlyphMarginLanesModel } from '../model.js';789const MAX_LANE = GlyphMarginLane.Right;1011export class GlyphMarginLanesModel implements IGlyphMarginLanesModel {12private lanes: Uint8Array;13private persist = 0;14private _requiredLanes = 1; // always render at least one lane1516constructor(maxLine: number) {17this.lanes = new Uint8Array(Math.ceil(((maxLine + 1) * MAX_LANE) / 8));18}1920public reset(maxLine: number) {21const bytes = Math.ceil(((maxLine + 1) * MAX_LANE) / 8);22if (this.lanes.length < bytes) {23this.lanes = new Uint8Array(bytes);24} else {25this.lanes.fill(0);26}27this._requiredLanes = 1;28}2930public get requiredLanes() {31return this._requiredLanes;32}3334public push(lane: GlyphMarginLane, range: Range, persist?: boolean): void {35if (persist) {36this.persist |= (1 << (lane - 1));37}38for (let i = range.startLineNumber; i <= range.endLineNumber; i++) {39const bit = (MAX_LANE * i) + (lane - 1);40this.lanes[bit >>> 3] |= (1 << (bit % 8));41this._requiredLanes = Math.max(this._requiredLanes, this.countAtLine(i));42}43}4445public getLanesAtLine(lineNumber: number): GlyphMarginLane[] {46const lanes: GlyphMarginLane[] = [];47let bit = MAX_LANE * lineNumber;48for (let i = 0; i < MAX_LANE; i++) {49if (this.persist & (1 << i) || this.lanes[bit >>> 3] & (1 << (bit % 8))) {50lanes.push(i + 1);51}52bit++;53}5455return lanes.length ? lanes : [GlyphMarginLane.Center];56}5758private countAtLine(lineNumber: number): number {59let bit = MAX_LANE * lineNumber;60let count = 0;61for (let i = 0; i < MAX_LANE; i++) {62if (this.persist & (1 << i) || this.lanes[bit >>> 3] & (1 << (bit % 8))) {63count++;64}65bit++;66}67return count;68}69}707172