@@ -309,19 +309,27 @@ export class Linkifier2 extends Disposable implements ILinkifier2 {
309
309
}
310
310
} ) ;
311
311
312
- // Add listener for rerendering
312
+ // Listen to viewport changes to re-render the link under the cursor (only when the line the
313
+ // link is on changes)
313
314
if ( this . _renderService ) {
314
315
this . _linkCacheDisposables . push ( this . _renderService . onRenderedViewportChange ( e => {
316
+ // Sanity check, this shouldn't happen in practice as this listener would be disposed
317
+ if ( ! this . _currentLink ) {
318
+ return ;
319
+ }
315
320
// When start is 0 a scroll most likely occurred, make sure links above the fold also get
316
321
// cleared.
317
322
const start = e . start === 0 ? 0 : e . start + 1 + this . _bufferService . buffer . ydisp ;
318
- const oldEvent = this . _currentLink ? this . _lastMouseEvent : undefined ;
319
- this . _clearCurrentLink ( start , e . end + 1 + this . _bufferService . buffer . ydisp ) ;
320
- if ( oldEvent && this . _element ) {
321
- // re-eval previously active link after changes
322
- const position = this . _positionFromMouseEvent ( oldEvent , this . _element , this . _mouseService ! ) ;
323
- if ( position ) {
324
- this . _askForLink ( position , false ) ;
323
+ const end = this . _bufferService . buffer . ydisp + 1 + e . end ;
324
+ // Only clear the link if the viewport change happened on this line
325
+ if ( this . _currentLink . link . range . start . y >= start && this . _currentLink . link . range . end . y <= end ) {
326
+ this . _clearCurrentLink ( start , end ) ;
327
+ if ( this . _lastMouseEvent && this . _element ) {
328
+ // re-eval previously active link after changes
329
+ const position = this . _positionFromMouseEvent ( this . _lastMouseEvent , this . _element , this . _mouseService ! ) ;
330
+ if ( position ) {
331
+ this . _askForLink ( position , false ) ;
332
+ }
325
333
}
326
334
}
327
335
} ) ) ;
0 commit comments