From 27af7700683a7abdc9d4088e02addc3c721a1571 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Wed, 6 May 2020 06:16:36 -0700 Subject: [PATCH] Remove intersecting lower priority links Fixes #2848 --- src/browser/Linkifier2.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/browser/Linkifier2.ts b/src/browser/Linkifier2.ts index f468e4a4..14ee5f66 100644 --- a/src/browser/Linkifier2.ts +++ b/src/browser/Linkifier2.ts @@ -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): void { + const occupiedCells = new Set(); + 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;