Skip to content

Commit

Permalink
Merge pull request xtermjs#4342 from Tyriar/4341
Browse files Browse the repository at this point in the history
Fix link event listener leak
  • Loading branch information
Tyriar committed Dec 20, 2022
2 parents 3142460 + 7b8ad8c commit 75075eb
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/browser/Linkifier2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,19 +309,27 @@ export class Linkifier2 extends Disposable implements ILinkifier2 {
}
});

// Add listener for rerendering
// Listen to viewport changes to re-render the link under the cursor (only when the line the
// link is on changes)
if (this._renderService) {
this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(e => {
// Sanity check, this shouldn't happen in practice as this listener would be disposed
if (!this._currentLink) {
return;
}
// When start is 0 a scroll most likely occurred, make sure links above the fold also get
// cleared.
const start = e.start === 0 ? 0 : e.start + 1 + this._bufferService.buffer.ydisp;
const oldEvent = this._currentLink ? this._lastMouseEvent : undefined;
this._clearCurrentLink(start, e.end + 1 + this._bufferService.buffer.ydisp);
if (oldEvent && this._element) {
// re-eval previously active link after changes
const position = this._positionFromMouseEvent(oldEvent, this._element, this._mouseService!);
if (position) {
this._askForLink(position, false);
const end = this._bufferService.buffer.ydisp + 1 + e.end;
// Only clear the link if the viewport change happened on this line
if (this._currentLink.link.range.start.y >= start && this._currentLink.link.range.end.y <= end) {
this._clearCurrentLink(start, end);
if (this._lastMouseEvent && this._element) {
// re-eval previously active link after changes
const position = this._positionFromMouseEvent(this._lastMouseEvent, this._element, this._mouseService!);
if (position) {
this._askForLink(position, false);
}
}
}
}));
Expand Down

0 comments on commit 75075eb

Please sign in to comment.