@@ -9,7 +9,7 @@ import { coalesce } from 'vs/base/common/arrays';
9
9
import { CancellationToken } from 'vs/base/common/cancellation' ;
10
10
import { KeyCode } from 'vs/base/common/keyCodes' ;
11
11
import { Disposable , DisposableStore , toDisposable } from 'vs/base/common/lifecycle' ;
12
- import { ContentWidgetPositionPreference , IActiveCodeEditor , ICodeEditor , IEditorMouseEvent , MouseTargetType } from 'vs/editor/browser/editorBrowser' ;
12
+ import { ContentWidgetPositionPreference , IActiveCodeEditor , ICodeEditor , IContentWidgetPosition , IEditorMouseEvent , MouseTargetType } from 'vs/editor/browser/editorBrowser' ;
13
13
import { ConfigurationChangedEvent , EditorOption } from 'vs/editor/common/config/editorOptions' ;
14
14
import { Position } from 'vs/editor/common/core/position' ;
15
15
import { Range } from 'vs/editor/common/core/range' ;
@@ -452,7 +452,6 @@ export class ContentHoverWidget extends ResizableContentWidget {
452
452
453
453
private _visibleData : ContentHoverVisibleData | undefined ;
454
454
private _positionPreference : ContentWidgetPositionPreference | undefined ;
455
- private _position : Position | undefined ;
456
455
457
456
private readonly _hover : HoverWidget = this . _register ( new HoverWidget ( ) ) ;
458
457
private readonly _hoverVisibleKey : IContextKey < boolean > ;
@@ -470,14 +469,6 @@ export class ContentHoverWidget extends ResizableContentWidget {
470
469
return this . _hoverVisibleKey . get ( ) ?? false ;
471
470
}
472
471
473
- get position ( ) : Position | undefined {
474
- return this . _position ;
475
- }
476
-
477
- set position ( position : Position | undefined ) {
478
- this . _position = position ;
479
- }
480
-
481
472
constructor (
482
473
_editor : ICodeEditor ,
483
474
@IContextKeyService _contextKeyService : IContextKeyService
@@ -504,6 +495,7 @@ export class ContentHoverWidget extends ResizableContentWidget {
504
495
} ) ) ;
505
496
this . _setHoverData ( undefined ) ;
506
497
this . _layout ( ) ;
498
+ this . _editor . addContentWidget ( this ) ;
507
499
}
508
500
509
501
public override dispose ( ) : void {
@@ -643,7 +635,6 @@ export class ContentHoverWidget extends ResizableContentWidget {
643
635
}
644
636
645
637
private _setHoverData ( hoverData : ContentHoverVisibleData | undefined ) : void {
646
- this . _position = hoverData ?. showAtPosition ;
647
638
this . _visibleData ?. disposables . dispose ( ) ;
648
639
this . _visibleData = hoverData ;
649
640
this . _hoverVisibleKey . set ( ! ! hoverData ) ;
@@ -687,9 +678,6 @@ export class ContentHoverWidget extends ResizableContentWidget {
687
678
}
688
679
689
680
private _render ( node : DocumentFragment , hoverData : ContentHoverVisibleData ) {
690
- if ( ! this . _hoverVisibleKey . get ( ) ) {
691
- this . _editor . addContentWidget ( this ) ;
692
- }
693
681
this . _setHoverData ( hoverData ) ;
694
682
this . _updateFont ( ) ;
695
683
this . _updateContent ( node ) ;
@@ -700,25 +688,26 @@ export class ContentHoverWidget extends ResizableContentWidget {
700
688
this . _editor . render ( ) ;
701
689
}
702
690
703
- private _setContentPosition ( hoverData : ContentHoverVisibleData , preference ?: ContentWidgetPositionPreference ) {
704
- this . _contentPosition = {
705
- position : hoverData . showAtPosition ,
706
- secondaryPosition : hoverData . showAtSecondaryPosition ,
707
- positionAffinity : hoverData . isBeforeContent ? PositionAffinity . LeftOfInjectedText : undefined ,
708
- preference : [ preference ?? ContentWidgetPositionPreference . ABOVE ]
691
+ override getPosition ( ) : IContentWidgetPosition | null {
692
+ if ( ! this . _visibleData ) {
693
+ return null ;
694
+ }
695
+ return {
696
+ position : this . _visibleData . showAtPosition ,
697
+ secondaryPosition : this . _visibleData . showAtSecondaryPosition ,
698
+ positionAffinity : this . _visibleData . isBeforeContent ? PositionAffinity . LeftOfInjectedText : undefined ,
699
+ preference : [ this . _positionPreference ?? ContentWidgetPositionPreference . ABOVE ]
709
700
} ;
710
701
}
711
702
712
703
public showAt ( node : DocumentFragment , hoverData : ContentHoverVisibleData ) : void {
713
704
if ( ! this . _editor || ! this . _editor . hasModel ( ) ) {
714
705
return ;
715
706
}
716
- this . _setContentPosition ( hoverData ) ;
717
707
this . _render ( node , hoverData ) ;
718
708
const widgetHeight = this . _getWidgetHeight ( ) ;
719
709
const widgetPosition = hoverData . showAtPosition ;
720
710
this . _positionPreference = this . _findPositionPreference ( widgetHeight , widgetPosition ) ?? ContentWidgetPositionPreference . ABOVE ;
721
- this . _setContentPosition ( hoverData , this . _positionPreference ) ;
722
711
723
712
// See https://github.com/microsoft/vscode/issues/140339
724
713
// TODO: Doing a second layout of the hover after force rendering the editor
@@ -733,13 +722,13 @@ export class ContentHoverWidget extends ResizableContentWidget {
733
722
if ( ! this . _visibleData ) {
734
723
return ;
735
724
}
725
+ const stoleFocus = this . _visibleData . stoleFocus ;
736
726
this . _setHoverData ( undefined ) ;
737
727
this . _resizableNode . maxSize = new dom . Dimension ( Infinity , Infinity ) ;
738
728
this . _resizableNode . clearSashHoverState ( ) ;
739
- this . _editor . removeContentWidget ( this ) ;
740
729
this . _hoverFocusedKey . set ( false ) ;
741
730
this . _editor . layoutContentWidget ( this ) ;
742
- if ( this . _visibleData . stoleFocus ) {
731
+ if ( stoleFocus ) {
743
732
this . _editor . focus ( ) ;
744
733
}
745
734
}
0 commit comments