@@ -6,6 +6,7 @@
|
||||
import { EventEmitter } from 'common/EventEmitter';
|
||||
import { Disposable } from 'common/Lifecycle';
|
||||
import { IDecorationService, IInternalDecoration } from 'common/services/Services';
|
||||
import { IColorRGB } from 'common/Types';
|
||||
import { IDecorationOptions, IDecoration, IMarker, IEvent } from 'xterm';
|
||||
|
||||
export class DecorationService extends Disposable implements IDecorationService {
|
||||
@@ -45,6 +46,15 @@ export class DecorationService extends Disposable implements IDecorationService
|
||||
return decoration;
|
||||
}
|
||||
|
||||
public *getDecorationsOnLine(line: number): IterableIterator<IInternalDecoration> {
|
||||
// TODO: This could be made much faster if _decorations was sorted by line (and col?)
|
||||
for (const d of this.decorations) {
|
||||
if (d.marker.line === line) {
|
||||
yield d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
for (const decoration of this._decorations) {
|
||||
this._onDecorationRemoved.fire(decoration);
|
||||
@@ -64,6 +74,32 @@ class Decoration extends Disposable implements IInternalDecoration {
|
||||
private _onDispose = this.register(new EventEmitter<void>());
|
||||
public readonly onDispose = this._onDispose.event;
|
||||
|
||||
// TODO: React to changes on options
|
||||
private _cachedBg: IColorRGB | undefined | null = null;
|
||||
public get backgroundColorRGB(): IColorRGB | undefined {
|
||||
if (this._cachedBg === null) {
|
||||
if (this.options.backgroundColor) {
|
||||
this._cachedBg = toColorRGB(this.options.backgroundColor);
|
||||
} else {
|
||||
this._cachedBg = undefined;
|
||||
}
|
||||
}
|
||||
return this._cachedBg;
|
||||
}
|
||||
|
||||
// TODO: React to changes on options
|
||||
private _cachedFg: IColorRGB | undefined | null = null;
|
||||
public get foregroundColorRGB(): IColorRGB | undefined {
|
||||
if (this._cachedFg === null) {
|
||||
if (this.options.foregroundColor) {
|
||||
this._cachedFg = toColorRGB(this.options.foregroundColor);
|
||||
} else {
|
||||
this._cachedFg = undefined;
|
||||
}
|
||||
}
|
||||
return this._cachedFg;
|
||||
}
|
||||
|
||||
constructor(
|
||||
public readonly options: IDecorationOptions
|
||||
) {
|
||||
@@ -73,6 +109,7 @@ class Decoration extends Disposable implements IInternalDecoration {
|
||||
this.options.overviewRulerOptions.position = 'full';
|
||||
}
|
||||
}
|
||||
|
||||
public override dispose(): void {
|
||||
if (this._isDisposed) {
|
||||
return;
|
||||
@@ -82,3 +119,11 @@ class Decoration extends Disposable implements IInternalDecoration {
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function toColorRGB(css: string): IColorRGB {
|
||||
// #rrggbb
|
||||
if (css.length === 7) {
|
||||
return [parseInt(css.slice(1, 3), 16), parseInt(css.slice(3, 5), 16), parseInt(css.slice(5, 7), 16)];
|
||||
}
|
||||
throw new Error('css.toColor: Unsupported css format');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user