Reduce duplicate with getDecorationsAtCell method
This commit is contained in:
@@ -167,6 +167,7 @@ export class MockDecorationService implements IDecorationService {
|
||||
public onDecorationRemoved = new EventEmitter<IInternalDecoration>().event;
|
||||
public registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined { return undefined; }
|
||||
public reset(): void { }
|
||||
public *getDecorationsOnLine(line: number): IterableIterator<IInternalDecoration> { }
|
||||
public *getDecorationsAtLine(line: number): IterableIterator<IInternalDecoration> { }
|
||||
public *getDecorationsAtCell(x: number, line: number): IterableIterator<IInternalDecoration> { }
|
||||
public dispose(): void { }
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ export class DecorationService extends Disposable implements IDecorationService
|
||||
this._decorations.length = 0;
|
||||
}
|
||||
|
||||
public *getDecorationsOnLine(line: number): IterableIterator<IInternalDecoration> {
|
||||
public *getDecorationsAtLine(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) {
|
||||
@@ -65,6 +65,20 @@ export class DecorationService extends Disposable implements IDecorationService
|
||||
}
|
||||
}
|
||||
|
||||
public *getDecorationsAtCell(x: number, line: number): IterableIterator<IInternalDecoration> {
|
||||
let xmin = 0;
|
||||
let xmax = 0;
|
||||
for (const d of this.decorations) {
|
||||
if (d.marker.line === line) {
|
||||
xmin = d.options.x ?? 0;
|
||||
xmax = xmin + (d.options.width ?? 1);
|
||||
if (x >= xmin && x < xmax) {
|
||||
yield d;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
for (const decoration of this._decorations) {
|
||||
this._onDecorationRemoved.fire(decoration);
|
||||
|
||||
@@ -309,8 +309,10 @@ export interface IDecorationService extends IDisposable {
|
||||
readonly onDecorationRemoved: IEvent<IInternalDecoration>;
|
||||
registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined;
|
||||
reset(): void;
|
||||
/** Iterates over the decorations on a line (in no particular order). */
|
||||
getDecorationsOnLine(line: number): IterableIterator<IInternalDecoration>;
|
||||
/** Iterates over the decorations at a line (in no particular order). */
|
||||
getDecorationsAtLine(line: number): IterableIterator<IInternalDecoration>;
|
||||
/** Iterates over the decorations at a cell (in no particular order). */
|
||||
getDecorationsAtCell(x: number, line: number): IterableIterator<IInternalDecoration>;
|
||||
}
|
||||
export interface IInternalDecoration extends IDecoration {
|
||||
readonly options: IDecorationOptions;
|
||||
|
||||
Reference in New Issue
Block a user