Files
azuredatastudio/src/vs/editor/common/view/overviewZoneManager.ts
Charles Gagnon 2bc6a0cd01 VS Code merge to df8fe74bd55313de0dd2303bc47a4aab0ca56b0e (#17979)
* Merge from vscode 504f934659740e9d41501cad9f162b54d7745ad9

* delete unused folders

* distro

* Bump build node version

* update chokidar

* FIx hygiene errors

* distro

* Fix extension lint issues

* Remove strict-vscode

* Add copyright header exemptions

* Bump vscode-extension-telemetry to fix webpacking issue with zone.js

* distro

* Fix failing tests (revert marked.js back to current one until we decide to update)

* Skip searchmodel test

* Fix mac build

* temp debug script loading

* Try disabling coverage

* log error too

* Revert "log error too"

This reverts commit af0183e5d4ab458fdf44b88fbfab9908d090526f.

* Revert "temp debug script loading"

This reverts commit 3d687d541c76db2c5b55626c78ae448d3c25089c.

* Add comments explaining coverage disabling

* Fix ansi_up loading issue

* Merge latest from ads

* Use newer option

* Fix compile

* add debug logging warn

* Always log stack

* log more

* undo debug

* Update to use correct base path (+cleanup)

* distro

* fix compile errors

* Remove strict-vscode

* Fix sql editors not showing

* Show db dropdown input & fix styling

* Fix more info in gallery

* Fix gallery asset requests

* Delete unused workflow

* Fix tapable resolutions for smoke test compile error

* Fix smoke compile

* Disable crash reporting

* Disable interactive

Co-authored-by: ADS Merger <karlb@microsoft.com>
2022-01-06 09:06:56 -08:00

232 lines
5.8 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const enum Constants {
MINIMUM_HEIGHT = 4
}
export class ColorZone {
_colorZoneBrand: void = undefined;
public readonly from: number;
public readonly to: number;
public readonly colorId: number;
constructor(from: number, to: number, colorId: number) {
this.from = from | 0;
this.to = to | 0;
this.colorId = colorId | 0;
}
public static compare(a: ColorZone, b: ColorZone): number {
if (a.colorId === b.colorId) {
if (a.from === b.from) {
return a.to - b.to;
}
return a.from - b.from;
}
return a.colorId - b.colorId;
}
}
/**
* A zone in the overview ruler
*/
export class OverviewRulerZone {
_overviewRulerZoneBrand: void = undefined;
public readonly startLineNumber: number;
public readonly endLineNumber: number;
public readonly color: string;
private _colorZone: ColorZone | null;
constructor(
startLineNumber: number,
endLineNumber: number,
color: string
) {
this.startLineNumber = startLineNumber;
this.endLineNumber = endLineNumber;
this.color = color;
this._colorZone = null;
}
public static compare(a: OverviewRulerZone, b: OverviewRulerZone): number {
if (a.color === b.color) {
if (a.startLineNumber === b.startLineNumber) {
return a.endLineNumber - b.endLineNumber;
}
return a.startLineNumber - b.startLineNumber;
}
return a.color < b.color ? -1 : 1;
}
public setColorZone(colorZone: ColorZone): void {
this._colorZone = colorZone;
}
public getColorZones(): ColorZone | null {
return this._colorZone;
}
}
export class OverviewZoneManager {
private readonly _getVerticalOffsetForLine: (lineNumber: number) => number;
private _zones: OverviewRulerZone[];
private _colorZonesInvalid: boolean;
private _lineHeight: number;
private _domWidth: number;
private _domHeight: number;
private _outerHeight: number;
private _pixelRatio: number;
private _lastAssignedId: number;
private readonly _color2Id: { [color: string]: number; };
private readonly _id2Color: string[];
constructor(getVerticalOffsetForLine: (lineNumber: number) => number) {
this._getVerticalOffsetForLine = getVerticalOffsetForLine;
this._zones = [];
this._colorZonesInvalid = false;
this._lineHeight = 0;
this._domWidth = 0;
this._domHeight = 0;
this._outerHeight = 0;
this._pixelRatio = 1;
this._lastAssignedId = 0;
this._color2Id = Object.create(null);
this._id2Color = [];
}
public getId2Color(): string[] {
return this._id2Color;
}
public setZones(newZones: OverviewRulerZone[]): void {
this._zones = newZones;
this._zones.sort(OverviewRulerZone.compare);
}
public setLineHeight(lineHeight: number): boolean {
if (this._lineHeight === lineHeight) {
return false;
}
this._lineHeight = lineHeight;
this._colorZonesInvalid = true;
return true;
}
public setPixelRatio(pixelRatio: number): void {
this._pixelRatio = pixelRatio;
this._colorZonesInvalid = true;
}
public getDOMWidth(): number {
return this._domWidth;
}
public getCanvasWidth(): number {
return this._domWidth * this._pixelRatio;
}
public setDOMWidth(width: number): boolean {
if (this._domWidth === width) {
return false;
}
this._domWidth = width;
this._colorZonesInvalid = true;
return true;
}
public getDOMHeight(): number {
return this._domHeight;
}
public getCanvasHeight(): number {
return this._domHeight * this._pixelRatio;
}
public setDOMHeight(height: number): boolean {
if (this._domHeight === height) {
return false;
}
this._domHeight = height;
this._colorZonesInvalid = true;
return true;
}
public getOuterHeight(): number {
return this._outerHeight;
}
public setOuterHeight(outerHeight: number): boolean {
if (this._outerHeight === outerHeight) {
return false;
}
this._outerHeight = outerHeight;
this._colorZonesInvalid = true;
return true;
}
public resolveColorZones(): ColorZone[] {
const colorZonesInvalid = this._colorZonesInvalid;
const lineHeight = Math.floor(this._lineHeight); // @perf
const totalHeight = Math.floor(this.getCanvasHeight()); // @perf
const outerHeight = Math.floor(this._outerHeight); // @perf
const heightRatio = totalHeight / outerHeight;
const halfMinimumHeight = Math.floor(Constants.MINIMUM_HEIGHT * this._pixelRatio / 2);
let allColorZones: ColorZone[] = [];
for (let i = 0, len = this._zones.length; i < len; i++) {
const zone = this._zones[i];
if (!colorZonesInvalid) {
const colorZone = zone.getColorZones();
if (colorZone) {
allColorZones.push(colorZone);
continue;
}
}
const y1 = Math.floor(heightRatio * (this._getVerticalOffsetForLine(zone.startLineNumber)));
const y2 = Math.floor(heightRatio * (this._getVerticalOffsetForLine(zone.endLineNumber) + lineHeight));
let ycenter = Math.floor((y1 + y2) / 2);
let halfHeight = (y2 - ycenter);
if (halfHeight < halfMinimumHeight) {
halfHeight = halfMinimumHeight;
}
if (ycenter - halfHeight < 0) {
ycenter = halfHeight;
}
if (ycenter + halfHeight > totalHeight) {
ycenter = totalHeight - halfHeight;
}
const color = zone.color;
let colorId = this._color2Id[color];
if (!colorId) {
colorId = (++this._lastAssignedId);
this._color2Id[color] = colorId;
this._id2Color[colorId] = color;
}
const colorZone = new ColorZone(ycenter - halfHeight, ycenter + halfHeight, colorId);
zone.setColorZone(colorZone);
allColorZones.push(colorZone);
}
this._colorZonesInvalid = false;
allColorZones.sort(ColorZone.compare);
return allColorZones;
}
}