Skip to content

Commit 9186c72

Browse files
authored
Merge pull request #5171 from Tyriar/links
Fix links sometimes not activating
2 parents f56675f + f764c0a commit 9186c72

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/browser/CoreBrowserTerminal.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ export class CoreBrowserTerminal extends CoreTerminal implements ITerminal {
6969
private _helperContainer: HTMLElement | undefined;
7070
private _compositionView: HTMLElement | undefined;
7171

72-
public linkifier: ILinkifier2 | undefined;
72+
private readonly _linkifier: MutableDisposable<ILinkifier2> = this._register(new MutableDisposable());
73+
public get linkifier(): ILinkifier2 | undefined { return this._linkifier.value; }
7374
private _overviewRulerRenderer: OverviewRulerRenderer | undefined;
7475
private _viewport: Viewport | undefined;
7576

@@ -485,7 +486,7 @@ export class CoreBrowserTerminal extends CoreTerminal implements ITerminal {
485486
this._mouseService = this._instantiationService.createInstance(MouseService);
486487
this._instantiationService.setService(IMouseService, this._mouseService);
487488

488-
this.linkifier = this._register(this._instantiationService.createInstance(Linkifier, this.screenElement));
489+
const linkifier = this._linkifier.value = this._register(this._instantiationService.createInstance(Linkifier, this.screenElement));
489490

490491
// Performance: Add viewport and helper elements from the fragment
491492
this.element.appendChild(fragment);
@@ -515,7 +516,7 @@ export class CoreBrowserTerminal extends CoreTerminal implements ITerminal {
515516
this._selectionService = this._register(this._instantiationService.createInstance(SelectionService,
516517
this.element,
517518
this.screenElement,
518-
this.linkifier
519+
linkifier
519520
));
520521
this._instantiationService.setService(ISelectionService, this._selectionService);
521522
this._register(this._selectionService.onRequestScrollLines(e => this.scrollLines(e.amount, e.suppressScrollEvent)));

src/browser/Linkifier.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export class Linkifier extends Disposable implements ILinkifier2 {
227227
return;
228228
}
229229

230-
if (this._mouseDownLink === this._currentLink && this._linkAtPosition(this._currentLink.link, position)) {
230+
if (this._mouseDownLink && linkEquals(this._mouseDownLink.link, this._currentLink.link) && this._linkAtPosition(this._currentLink.link, position)) {
231231
this._currentLink.link.activate(event, this._currentLink.link.text);
232232
}
233233
}
@@ -391,3 +391,13 @@ export class Linkifier extends Disposable implements ILinkifier2 {
391391
return { x1, y1, x2, y2, cols: this._bufferService.cols, fg };
392392
}
393393
}
394+
395+
function linkEquals(a: ILink, b: ILink): boolean {
396+
return (
397+
a.text === b.text &&
398+
a.range.start.x === b.range.start.x &&
399+
a.range.start.y === b.range.start.y &&
400+
a.range.end.x === b.range.end.x &&
401+
a.range.end.y === b.range.end.y
402+
);
403+
}

0 commit comments

Comments
 (0)