@@ -371,6 +371,12 @@ export class ModesHoverController extends Disposable implements IEditorContribut
371
371
}
372
372
}
373
373
374
+ enum HoverFocusBehavior {
375
+ NoAutoFocus = 'noAutoFocus' ,
376
+ FocusIfVisible = 'focusIfVisible' ,
377
+ AutoFocusImmediately = 'autoFocusImmediately'
378
+ }
379
+
374
380
class ShowOrFocusHoverAction extends EditorAction {
375
381
376
382
constructor ( ) {
@@ -381,8 +387,7 @@ class ShowOrFocusHoverAction extends EditorAction {
381
387
comment : [
382
388
'Label for action that will trigger the showing/focusing of a hover in the editor.' ,
383
389
'If the hover is not visible, it will show the hover.' ,
384
- 'This allows for users to show the hover without using the mouse.' ,
385
- 'If the hover is already visible, it will take focus.'
390
+ 'This allows for users to show the hover without using the mouse.'
386
391
]
387
392
} , "Show or Focus Hover" ) ,
388
393
metadata : {
@@ -393,9 +398,14 @@ class ShowOrFocusHoverAction extends EditorAction {
393
398
type : 'object' ,
394
399
properties : {
395
400
'focus' : {
396
- description : 'Controls if when triggered with the keyboard, the hover should take focus immediately.' ,
397
- type : 'boolean' ,
398
- default : false
401
+ description : 'Controls if and when the hover should take focus upon being triggered by this action.' ,
402
+ enum : [ HoverFocusBehavior . NoAutoFocus , HoverFocusBehavior . FocusIfVisible , HoverFocusBehavior . AutoFocusImmediately ] ,
403
+ enumDescriptions : [
404
+ nls . localize ( 'showOrFocusHover.focus.noAutoFocus' , 'The hover will not automatically take focus.' ) ,
405
+ nls . localize ( 'showOrFocusHover.focus.focusIfVisible' , 'The hover will take focus only if it is already visible.' ) ,
406
+ nls . localize ( 'showOrFocusHover.focus.autoFocusImmediately' , 'The hover will automatically take focus when it appears.' ) ,
407
+ ] ,
408
+ default : HoverFocusBehavior . FocusIfVisible ,
399
409
}
400
410
} ,
401
411
}
@@ -419,14 +429,31 @@ class ShowOrFocusHoverAction extends EditorAction {
419
429
if ( ! controller ) {
420
430
return ;
421
431
}
422
- const position = editor . getPosition ( ) ;
423
- const range = new Range ( position . lineNumber , position . column , position . lineNumber , position . column ) ;
424
- const focus = editor . getOption ( EditorOption . accessibilitySupport ) === AccessibilitySupport . Enabled || ! ! args ?. focus ;
432
+
433
+ const focusArgument = args ?. focus ;
434
+ let focusOption = HoverFocusBehavior . FocusIfVisible ;
435
+ if ( focusArgument in HoverFocusBehavior ) {
436
+ focusOption = focusArgument ;
437
+ } else if ( typeof focusArgument === 'boolean' && focusArgument ) {
438
+ focusOption = HoverFocusBehavior . AutoFocusImmediately ;
439
+ }
440
+
441
+ const showContentHover = ( focus : boolean ) => {
442
+ const position = editor . getPosition ( ) ;
443
+ const range = new Range ( position . lineNumber , position . column , position . lineNumber , position . column ) ;
444
+ controller . showContentHover ( range , HoverStartMode . Immediate , HoverStartSource . Keyboard , focus ) ;
445
+ } ;
446
+
447
+ const accessibilitySupportEnabled = editor . getOption ( EditorOption . accessibilitySupport ) === AccessibilitySupport . Enabled ;
425
448
426
449
if ( controller . isHoverVisible ) {
427
- controller . focus ( ) ;
450
+ if ( focusOption !== HoverFocusBehavior . NoAutoFocus ) {
451
+ controller . focus ( ) ;
452
+ } else {
453
+ showContentHover ( accessibilitySupportEnabled ) ;
454
+ }
428
455
} else {
429
- controller . showContentHover ( range , HoverStartMode . Immediate , HoverStartSource . Keyboard , focus ) ;
456
+ showContentHover ( accessibilitySupportEnabled || focusOption === HoverFocusBehavior . AutoFocusImmediately ) ;
430
457
}
431
458
}
432
459
}
0 commit comments