5
5
6
6
import { EventType } from 'vs/base/browser/dom' ;
7
7
import { IMarkdownString , MarkdownString } from 'vs/base/common/htmlContent' ;
8
- import { DisposableStore , dispose , IDisposable } from 'vs/base/common/lifecycle' ;
8
+ import { DisposableStore , dispose , IDisposable , toDisposable } from 'vs/base/common/lifecycle' ;
9
9
import { Schemas } from 'vs/base/common/network' ;
10
10
import { posix , win32 } from 'vs/base/common/path' ;
11
11
import { isMacintosh , OperatingSystem , OS } from 'vs/base/common/platform' ;
@@ -33,6 +33,7 @@ import { ITerminalConfiguration, ITerminalProcessManager, TERMINAL_CONFIG_SECTIO
33
33
import { IHoverAction } from 'vs/workbench/services/hover/browser/hover' ;
34
34
import type { ILink , ILinkProvider , IViewportRange , Terminal } from 'xterm' ;
35
35
import { convertBufferRangeToViewport } from 'vs/workbench/contrib/terminal/browser/links/terminalLinkHelpers' ;
36
+ import { RunOnceScheduler } from 'vs/base/common/async' ;
36
37
37
38
export type XtermLinkMatcherHandler = ( event : MouseEvent | undefined , link : string ) => Promise < void > ;
38
39
export type XtermLinkMatcherValidationCallback = ( uri : string , callback : ( isValid : boolean ) => void ) => void ;
@@ -94,8 +95,14 @@ export class TerminalLinkManager extends DisposableStore {
94
95
95
96
this . _registerStandardLinkProviders ( ) ;
96
97
98
+ let activeHoverDisposable : IDisposable | undefined ;
99
+ let activeTooltipScheduler : RunOnceScheduler | undefined ;
100
+ this . add ( toDisposable ( ( ) => {
101
+ activeHoverDisposable ?. dispose ( ) ;
102
+ activeTooltipScheduler ?. dispose ( ) ;
103
+ } ) ) ;
97
104
this . _xterm . options . linkHandler = {
98
- activate : ( e , text ) => {
105
+ activate : ( _ , text ) => {
99
106
this . _openers . get ( TerminalBuiltinLinkType . Url ) ?. open ( {
100
107
type : TerminalBuiltinLinkType . Url ,
101
108
text,
@@ -104,23 +111,29 @@ export class TerminalLinkManager extends DisposableStore {
104
111
} ) ;
105
112
} ,
106
113
hover : ( e , text , range ) => {
107
- const core = ( this . _xterm as any ) . _core as IXtermCore ;
108
- const cellDimensions = {
109
- width : core . _renderService . dimensions . actualCellWidth ,
110
- height : core . _renderService . dimensions . actualCellHeight
111
- } ;
112
- const terminalDimensions = {
113
- width : this . _xterm . cols ,
114
- height : this . _xterm . rows
115
- } ;
116
- this . _showHover ( {
117
- viewportRange : convertBufferRangeToViewport ( range , this . _xterm . buffer . active . viewportY ) ,
118
- cellDimensions,
119
- terminalDimensions
120
- } , this . _getLinkHoverString ( text , text ) , undefined , ( text ) => this . _xterm . options . linkHandler ! . activate ( e , text , range ) ) ;
121
- } ,
122
- leave : ( e , text ) => {
123
- console . log ( 'leave' ) ;
114
+ activeHoverDisposable ?. dispose ( ) ;
115
+ activeHoverDisposable = undefined ;
116
+ activeTooltipScheduler ?. dispose ( ) ;
117
+ activeTooltipScheduler = new RunOnceScheduler ( ( ) => {
118
+ const core = ( this . _xterm as any ) . _core as IXtermCore ;
119
+ const cellDimensions = {
120
+ width : core . _renderService . dimensions . actualCellWidth ,
121
+ height : core . _renderService . dimensions . actualCellHeight
122
+ } ;
123
+ const terminalDimensions = {
124
+ width : this . _xterm . cols ,
125
+ height : this . _xterm . rows
126
+ } ;
127
+ activeHoverDisposable = this . _showHover ( {
128
+ viewportRange : convertBufferRangeToViewport ( range , this . _xterm . buffer . active . viewportY ) ,
129
+ cellDimensions,
130
+ terminalDimensions
131
+ } , this . _getLinkHoverString ( text , text ) , undefined , ( text ) => this . _xterm . options . linkHandler ?. activate ( e , text , range ) ) ;
132
+ // Clear out scheduler until next hover event
133
+ activeTooltipScheduler ?. dispose ( ) ;
134
+ activeTooltipScheduler = undefined ;
135
+ } , this . _configurationService . getValue ( 'workbench.hover.delay' ) ) ;
136
+ activeTooltipScheduler . schedule ( ) ;
124
137
}
125
138
} ;
126
139
}
@@ -267,14 +280,16 @@ export class TerminalLinkManager extends DisposableStore {
267
280
actions : IHoverAction [ ] | undefined ,
268
281
linkHandler : ( url : string ) => void ,
269
282
link ?: TerminalLink
270
- ) {
283
+ ) : IDisposable | undefined {
271
284
if ( this . _widgetManager ) {
272
285
const widget = this . _instantiationService . createInstance ( TerminalHover , targetOptions , text , actions , linkHandler ) ;
273
286
const attached = this . _widgetManager . attachWidget ( widget ) ;
274
287
if ( attached ) {
275
288
link ?. onInvalidated ( ( ) => attached . dispose ( ) ) ;
276
289
}
290
+ return attached ;
277
291
}
292
+ return undefined ;
278
293
}
279
294
280
295
setWidgetManager ( widgetManager : TerminalWidgetManager ) : void {
0 commit comments