Skip to content

Commit

Permalink
Remove intersecting lower priority links
Browse files Browse the repository at this point in the history
Fixes #2848
  • Loading branch information
Tyriar committed May 6, 2020
1 parent f9adf8a commit 27af770
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/browser/Linkifier2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,39 @@ export class Linkifier2 extends Disposable implements ILinkifier2 {
const linksWithState: ILinkWithState[] | undefined = links?.map(link => ({ link }));
this._activeProviderReplies?.set(i, linksWithState);
linkProvided = this._checkLinkProviderResult(i, position, linkProvided);

// If all providers have responded, remove lower priority links that intersect ranges of
// higher priority links
if (this._activeProviderReplies?.size === this._linkProviders.length) {
this._removeIntersectingLinks(position.y, this._activeProviderReplies);
}
});
}
});
}

private _removeIntersectingLinks(y: number, replies: Map<Number, ILinkWithState[] | undefined>): void {
const occupiedCells = new Set<number>();
for (let i = 0; i < replies.size; i++) {
const providerReply = replies.get(i);
if (!providerReply) {
continue;
}
for (let i = 0; i < providerReply.length; i++) {
const linkWithState = providerReply[i];
const startX = linkWithState.link.range.start.y < y ? 0 : linkWithState.link.range.start.x;
const endX = linkWithState.link.range.end.y > y ? this._bufferService.cols : linkWithState.link.range.end.x;
for (let x = startX; x <= endX; x++) {
if (occupiedCells.has(x)) {
providerReply.splice(i--, 1);
break;
}
occupiedCells.add(x);
}
}
}
}

private _checkLinkProviderResult(index: number, position: IBufferCellPosition, linkProvided: boolean): boolean {
if (!this._activeProviderReplies) {
return linkProvided;
Expand Down

0 comments on commit 27af770

Please sign in to comment.