@@ -16,7 +16,7 @@ import { Range } from 'vs/editor/common/core/range';
16
16
import { IModelDecoration , PositionAffinity } from 'vs/editor/common/model' ;
17
17
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel' ;
18
18
import { TokenizationRegistry } from 'vs/editor/common/languages' ;
19
- import { HoverOperation , HoverStartMode , IHoverComputer } from 'vs/editor/contrib/hover/browser/hoverOperation' ;
19
+ import { HoverOperation , HoverStartMode , HoverStartSource , IHoverComputer } from 'vs/editor/contrib/hover/browser/hoverOperation' ;
20
20
import { HoverAnchor , HoverAnchorType , HoverParticipantRegistry , HoverRangeAnchor , IEditorHoverColorPickerWidget , IEditorHoverAction , IEditorHoverParticipant , IEditorHoverRenderContext , IEditorHoverStatusBar , IHoverPart } from 'vs/editor/contrib/hover/browser/hoverTypes' ;
21
21
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
22
22
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
@@ -104,25 +104,25 @@ export class ContentHoverController extends Disposable {
104
104
}
105
105
106
106
if ( anchorCandidates . length === 0 ) {
107
- return this . _startShowingOrUpdateHover ( null , HoverStartMode . Delayed , false , mouseEvent ) ;
107
+ return this . _startShowingOrUpdateHover ( null , HoverStartMode . Delayed , HoverStartSource . Mouse , false , mouseEvent ) ;
108
108
}
109
109
110
110
anchorCandidates . sort ( ( a , b ) => b . priority - a . priority ) ;
111
- return this . _startShowingOrUpdateHover ( anchorCandidates [ 0 ] , HoverStartMode . Delayed , false , mouseEvent ) ;
111
+ return this . _startShowingOrUpdateHover ( anchorCandidates [ 0 ] , HoverStartMode . Delayed , HoverStartSource . Mouse , false , mouseEvent ) ;
112
112
}
113
113
114
- public startShowingAtRange ( range : Range , mode : HoverStartMode , focus : boolean ) : void {
115
- this . _startShowingOrUpdateHover ( new HoverRangeAnchor ( 0 , range , undefined , undefined ) , mode , focus , null ) ;
114
+ public startShowingAtRange ( range : Range , mode : HoverStartMode , source : HoverStartSource , focus : boolean ) : void {
115
+ this . _startShowingOrUpdateHover ( new HoverRangeAnchor ( 0 , range , undefined , undefined ) , mode , source , focus , null ) ;
116
116
}
117
117
118
118
/**
119
119
* Returns true if the hover shows now or will show.
120
120
*/
121
- private _startShowingOrUpdateHover ( anchor : HoverAnchor | null , mode : HoverStartMode , focus : boolean , mouseEvent : IEditorMouseEvent | null ) : boolean {
121
+ private _startShowingOrUpdateHover ( anchor : HoverAnchor | null , mode : HoverStartMode , source : HoverStartSource , focus : boolean , mouseEvent : IEditorMouseEvent | null ) : boolean {
122
122
if ( ! this . _widget . position || ! this . _currentResult ) {
123
123
// The hover is not visible
124
124
if ( anchor ) {
125
- this . _startHoverOperationIfNecessary ( anchor , mode , focus , false ) ;
125
+ this . _startHoverOperationIfNecessary ( anchor , mode , source , focus , false ) ;
126
126
return true ;
127
127
}
128
128
return false ;
@@ -135,7 +135,7 @@ export class ContentHoverController extends Disposable {
135
135
// The mouse is getting closer to the hover, so we will keep the hover untouched
136
136
// But we will kick off a hover update at the new anchor, insisting on keeping the hover visible.
137
137
if ( anchor ) {
138
- this . _startHoverOperationIfNecessary ( anchor , mode , focus , true ) ;
138
+ this . _startHoverOperationIfNecessary ( anchor , mode , source , focus , true ) ;
139
139
}
140
140
return true ;
141
141
}
@@ -153,18 +153,18 @@ export class ContentHoverController extends Disposable {
153
153
if ( ! anchor . canAdoptVisibleHover ( this . _currentResult . anchor , this . _widget . position ) ) {
154
154
// The new anchor is not compatible with the previous anchor
155
155
this . _setCurrentResult ( null ) ;
156
- this . _startHoverOperationIfNecessary ( anchor , mode , focus , false ) ;
156
+ this . _startHoverOperationIfNecessary ( anchor , mode , source , focus , false ) ;
157
157
return true ;
158
158
}
159
159
160
160
// We aren't getting any closer to the hover, so we will filter existing results
161
161
// and keep those which also apply to the new anchor.
162
162
this . _setCurrentResult ( this . _currentResult . filter ( anchor ) ) ;
163
- this . _startHoverOperationIfNecessary ( anchor , mode , focus , false ) ;
163
+ this . _startHoverOperationIfNecessary ( anchor , mode , source , focus , false ) ;
164
164
return true ;
165
165
}
166
166
167
- private _startHoverOperationIfNecessary ( anchor : HoverAnchor , mode : HoverStartMode , focus : boolean , insistOnKeepingHoverVisible : boolean ) : void {
167
+ private _startHoverOperationIfNecessary ( anchor : HoverAnchor , mode : HoverStartMode , source : HoverStartSource , focus : boolean , insistOnKeepingHoverVisible : boolean ) : void {
168
168
if ( this . _computer . anchor && this . _computer . anchor . equals ( anchor ) ) {
169
169
// We have to start a hover operation at the exact same anchor as before, so no work is needed
170
170
return ;
@@ -173,6 +173,7 @@ export class ContentHoverController extends Disposable {
173
173
this . _hoverOperation . cancel ( ) ;
174
174
this . _computer . anchor = anchor ;
175
175
this . _computer . shouldFocus = focus ;
176
+ this . _computer . source = source ;
176
177
this . _computer . insistOnKeepingHoverVisible = insistOnKeepingHoverVisible ;
177
178
this . _hoverOperation . start ( mode ) ;
178
179
}
@@ -203,6 +204,10 @@ export class ContentHoverController extends Disposable {
203
204
return this . _widget . isColorPickerVisible ;
204
205
}
205
206
207
+ public isVisibleFromKeyboard ( ) : boolean {
208
+ return this . _widget . isVisibleFromKeyboard ;
209
+ }
210
+
206
211
public containsNode ( node : Node ) : boolean {
207
212
return this . _widget . getDomNode ( ) . contains ( node ) ;
208
213
}
@@ -286,6 +291,7 @@ export class ContentHoverController extends Disposable {
286
291
showAtSecondaryPosition ,
287
292
this . _editor . getOption ( EditorOption . hover ) . above ,
288
293
this . _computer . shouldFocus ,
294
+ this . _computer . source ,
289
295
isBeforeContent ,
290
296
anchor . initialMousePosX ,
291
297
anchor . initialMousePosY ,
@@ -379,6 +385,7 @@ class ContentHoverVisibleData {
379
385
public readonly showAtSecondaryPosition : Position ,
380
386
public readonly preferAbove : boolean ,
381
387
public readonly stoleFocus : boolean ,
388
+ public readonly source : HoverStartSource ,
382
389
public readonly isBeforeContent : boolean ,
383
390
public initialMousePosX : number | undefined ,
384
391
public initialMousePosY : number | undefined ,
@@ -408,6 +415,10 @@ export class ContentHoverWidget extends Disposable implements IContentWidget {
408
415
return Boolean ( this . _visibleData ?. colorPicker ) ;
409
416
}
410
417
418
+ public get isVisibleFromKeyboard ( ) : boolean {
419
+ return ( this . _visibleData ?. source === HoverStartSource . Keyboard ) ;
420
+ }
421
+
411
422
constructor (
412
423
private readonly _editor : ICodeEditor ,
413
424
@IContextKeyService private readonly _contextKeyService : IContextKeyService ,
@@ -613,6 +624,10 @@ class ContentHoverComputer implements IHoverComputer<IHoverPart> {
613
624
public get shouldFocus ( ) : boolean { return this . _shouldFocus ; }
614
625
public set shouldFocus ( value : boolean ) { this . _shouldFocus = value ; }
615
626
627
+ private _source : HoverStartSource = HoverStartSource . Mouse ;
628
+ public get source ( ) : HoverStartSource { return this . _source ; }
629
+ public set source ( value : HoverStartSource ) { this . _source = value ; }
630
+
616
631
private _insistOnKeepingHoverVisible : boolean = false ;
617
632
public get insistOnKeepingHoverVisible ( ) : boolean { return this . _insistOnKeepingHoverVisible ; }
618
633
public set insistOnKeepingHoverVisible ( value : boolean ) { this . _insistOnKeepingHoverVisible = value ; }
0 commit comments