@@ -294,7 +294,7 @@ export class ContentHoverController extends Disposable {
294
294
} ) ) ;
295
295
}
296
296
297
- this . _widget . showAt ( fragment , new ContentHoverData (
297
+ this . _widget . showAt ( fragment , new HoverData (
298
298
colorPicker ,
299
299
showAtPosition ,
300
300
showAtSecondaryPosition ,
@@ -428,7 +428,7 @@ class FilteredHoverResult extends HoverResult {
428
428
}
429
429
}
430
430
431
- class ContentHoverData {
431
+ class HoverData {
432
432
433
433
public closestMouseDistance : number | undefined = undefined ;
434
434
@@ -455,19 +455,19 @@ export class ResizableHoverWidget extends MultiplePersistedSizeResizableContentW
455
455
public static ID = 'editor.contrib.resizableContentHoverWidget' ;
456
456
457
457
private _disposableStore = new DisposableStore ( ) ;
458
- private _visibleData : ContentHoverData | undefined ;
459
- private _renderingAbove : ContentWidgetPositionPreference | undefined ;
458
+ private _hoverData : HoverData | undefined ;
459
+ private _positionPreference : ContentWidgetPositionPreference | undefined ;
460
460
461
461
private readonly _hoverWidget : HoverWidget = this . _disposableStore . add ( new HoverWidget ( ) ) ;
462
462
private readonly _hoverVisibleKey : IContextKey < boolean > ;
463
463
private readonly _hoverFocusedKey : IContextKey < boolean > ;
464
464
465
465
public get isColorPickerVisible ( ) : boolean {
466
- return Boolean ( this . _visibleData ?. colorPicker ) ;
466
+ return Boolean ( this . _hoverData ?. colorPicker ) ;
467
467
}
468
468
469
469
public get isVisibleFromKeyboard ( ) : boolean {
470
- return ( this . _visibleData ?. source === HoverStartSource . Keyboard ) ;
470
+ return ( this . _hoverData ?. source === HoverStartSource . Keyboard ) ;
471
471
}
472
472
473
473
public get isVisible ( ) : boolean {
@@ -498,13 +498,13 @@ export class ResizableHoverWidget extends MultiplePersistedSizeResizableContentW
498
498
this . _disposableStore . add ( focusTracker . onDidBlur ( ( ) => {
499
499
this . _hoverFocusedKey . set ( false ) ;
500
500
} ) ) ;
501
- this . _setVisibleData ( undefined ) ;
501
+ this . _setHoverData ( undefined ) ;
502
502
this . _layout ( ) ;
503
503
}
504
504
505
505
public override dispose ( ) : void {
506
506
super . dispose ( ) ;
507
- this . _visibleData ?. disposables . dispose ( ) ;
507
+ this . _hoverData ?. disposables . dispose ( ) ;
508
508
this . _disposableStore . dispose ( ) ;
509
509
this . _editor . removeContentWidget ( this ) ;
510
510
}
@@ -563,17 +563,17 @@ export class ResizableHoverWidget extends MultiplePersistedSizeResizableContentW
563
563
const width = size . width - 2 * SASH_WIDTH_MINUS_BORDER ;
564
564
const height = size . height - 2 * SASH_WIDTH_MINUS_BORDER ;
565
565
this . _setHoverWidgetDimensions ( width , height ) ;
566
- // measure if has horizontal scorllbar after setting the dimensions
566
+ // measure if widget has horizontal scrollbar after setting the dimensions
567
567
if ( this . _hasHorizontalScrollbar ( ) ) {
568
568
this . _adjustContentsBottomPadding ( ) ;
569
569
this . _setContentsDomNodeDimensions ( width , height - SCROLLBAR_WIDTH ) ;
570
570
}
571
571
}
572
572
573
573
private _setResizableNodeMaxDimensions ( ) {
574
- const maxRenderingWidth = this . _findMaximumRenderingWidth ( ) ;
575
- const maxRenderingHeight = this . _findMaximumRenderingHeight ( ) ;
576
- this . _resizableNode . maxSize = new dom . Dimension ( maxRenderingWidth ?? Infinity , maxRenderingHeight ?? Infinity ) ;
574
+ const maxRenderingWidth = this . _findMaximumRenderingWidth ( ) ?? Infinity ;
575
+ const maxRenderingHeight = this . _findMaximumRenderingHeight ( ) ?? Infinity ;
576
+ this . _resizableNode . maxSize = new dom . Dimension ( maxRenderingWidth , maxRenderingHeight ) ;
577
577
}
578
578
579
579
override _resize ( size : dom . Dimension ) {
@@ -584,11 +584,11 @@ export class ResizableHoverWidget extends MultiplePersistedSizeResizableContentW
584
584
}
585
585
586
586
private _findAvailableSpaceVertically ( ) : number | undefined {
587
- if ( ! this . _visibleData ?. showAtPosition ) {
587
+ const position = this . _hoverData ?. showAtPosition ;
588
+ if ( ! position ) {
588
589
return ;
589
590
}
590
- const position = this . _visibleData . showAtPosition ;
591
- return this . _renderingAbove === ContentWidgetPositionPreference . ABOVE ? this . _availableVerticalSpaceAbove ( position ) : this . _availableVerticalSpaceBelow ( position ) ;
591
+ return this . _positionPreference === ContentWidgetPositionPreference . ABOVE ? this . _availableVerticalSpaceAbove ( position ) : this . _availableVerticalSpaceBelow ( position ) ;
592
592
}
593
593
594
594
private _findAvailableSpaceHorizontally ( ) : number | undefined {
@@ -621,38 +621,38 @@ export class ResizableHoverWidget extends MultiplePersistedSizeResizableContentW
621
621
}
622
622
623
623
public isMouseGettingCloser ( posx : number , posy : number ) : boolean {
624
- if ( ! this . _visibleData ) {
624
+ if ( ! this . _hoverData ) {
625
625
return false ;
626
626
}
627
- if ( typeof this . _visibleData . initialMousePosX === 'undefined' || typeof this . _visibleData . initialMousePosY === 'undefined' ) {
628
- this . _visibleData . initialMousePosX = posx ;
629
- this . _visibleData . initialMousePosY = posy ;
627
+ if ( typeof this . _hoverData . initialMousePosX === 'undefined' || typeof this . _hoverData . initialMousePosY === 'undefined' ) {
628
+ this . _hoverData . initialMousePosX = posx ;
629
+ this . _hoverData . initialMousePosY = posy ;
630
630
return false ;
631
631
}
632
632
633
633
const widgetRect = dom . getDomNodePagePosition ( this . getDomNode ( ) ) ;
634
- if ( typeof this . _visibleData . closestMouseDistance === 'undefined' ) {
635
- this . _visibleData . closestMouseDistance = computeDistanceFromPointToRectangle ( this . _visibleData . initialMousePosX , this . _visibleData . initialMousePosY , widgetRect . left , widgetRect . top , widgetRect . width , widgetRect . height ) ;
634
+ if ( typeof this . _hoverData . closestMouseDistance === 'undefined' ) {
635
+ this . _hoverData . closestMouseDistance = computeDistanceFromPointToRectangle ( this . _hoverData . initialMousePosX , this . _hoverData . initialMousePosY , widgetRect . left , widgetRect . top , widgetRect . width , widgetRect . height ) ;
636
636
}
637
637
const distance = computeDistanceFromPointToRectangle ( posx , posy , widgetRect . left , widgetRect . top , widgetRect . width , widgetRect . height ) ;
638
- if ( distance > this . _visibleData . closestMouseDistance + 4 /* tolerance of 4 pixels */ ) {
638
+ if ( distance > this . _hoverData . closestMouseDistance + 4 /* tolerance of 4 pixels */ ) {
639
639
// The mouse is getting farther away
640
640
return false ;
641
641
}
642
- this . _visibleData . closestMouseDistance = Math . min ( this . _visibleData . closestMouseDistance , distance ) ;
642
+ this . _hoverData . closestMouseDistance = Math . min ( this . _hoverData . closestMouseDistance , distance ) ;
643
643
return true ;
644
644
}
645
645
646
646
private _setWidgetPosition ( position : Position | undefined ) {
647
647
this . _position = position ;
648
648
}
649
649
650
- private _setVisibleData ( visibleData : ContentHoverData | undefined ) : void {
651
- this . _setWidgetPosition ( visibleData ?. showAtPosition ) ;
652
- this . _visibleData ?. disposables . dispose ( ) ;
653
- this . _visibleData = visibleData ;
654
- this . _hoverVisibleKey . set ( ! ! visibleData ) ;
655
- this . _hoverWidget . containerDomNode . classList . toggle ( 'hidden' , ! visibleData ) ;
650
+ private _setHoverData ( hoverData : HoverData | undefined ) : void {
651
+ this . _setWidgetPosition ( hoverData ?. showAtPosition ) ;
652
+ this . _hoverData ?. disposables . dispose ( ) ;
653
+ this . _hoverData = hoverData ;
654
+ this . _hoverVisibleKey . set ( ! ! hoverData ) ;
655
+ this . _hoverWidget . containerDomNode . classList . toggle ( 'hidden' , ! hoverData ) ;
656
656
}
657
657
658
658
private _layout ( ) : void {
@@ -694,63 +694,61 @@ export class ResizableHoverWidget extends MultiplePersistedSizeResizableContentW
694
694
this . _setContentsDomNodeMaxDimensions ( width , height ) ;
695
695
}
696
696
697
- private _render ( node : DocumentFragment , visibleData : ContentHoverData ) {
697
+ private _render ( node : DocumentFragment , hoverData : HoverData ) {
698
698
if ( ! this . _hoverVisibleKey . get ( ) ) {
699
699
this . _editor . addContentWidget ( this ) ;
700
700
}
701
- this . _setVisibleData ( visibleData ) ;
701
+ this . _setHoverData ( hoverData ) ;
702
702
this . _updateFont ( ) ;
703
703
this . _updateContent ( node ) ;
704
704
this . _updateContentsDomNodeMaxDimensions ( ) ;
705
- if ( ! this . findPersistedSize ( ) ) {
706
- this . onContentsChanged ( ) ;
707
- // Simply force a synchronous render on the editor
708
- // such that the widget does not really render with left = '0px'
709
- this . _editor . render ( ) ;
710
- }
705
+ this . onContentsChanged ( ) ;
706
+ // Simply force a synchronous render on the editor
707
+ // such that the widget does not really render with left = '0px'
708
+ this . _editor . render ( ) ;
711
709
}
712
710
713
- private _setContentPosition ( visibleData : ContentHoverData , preference ?: ContentWidgetPositionPreference ) {
711
+ private _setContentPosition ( hoverData : HoverData , preference ?: ContentWidgetPositionPreference ) {
714
712
this . _contentPosition = {
715
- position : visibleData . showAtPosition ,
716
- secondaryPosition : visibleData . showAtSecondaryPosition ,
717
- positionAffinity : visibleData . isBeforeContent ? PositionAffinity . LeftOfInjectedText : undefined ,
713
+ position : hoverData . showAtPosition ,
714
+ secondaryPosition : hoverData . showAtSecondaryPosition ,
715
+ positionAffinity : hoverData . isBeforeContent ? PositionAffinity . LeftOfInjectedText : undefined ,
718
716
preference : [ preference ?? ContentWidgetPositionPreference . ABOVE ]
719
717
} ;
720
718
}
721
719
722
- public showAt ( node : DocumentFragment , visibleData : ContentHoverData ) : void {
720
+ public showAt ( node : DocumentFragment , hoverData : HoverData ) : void {
723
721
if ( ! this . _editor || ! this . _editor . hasModel ( ) ) {
724
722
return ;
725
723
}
726
- this . _setContentPosition ( visibleData ) ;
727
- this . _render ( node , visibleData ) ;
724
+ this . _setContentPosition ( hoverData ) ;
725
+ this . _render ( node , hoverData ) ;
728
726
const widgetHeight = this . _getWidgetHeight ( ) ;
729
- const widgetPosition = visibleData . showAtPosition ;
730
- this . _renderingAbove = this . _findRenderingPreference ( widgetHeight , widgetPosition ) ?? ContentWidgetPositionPreference . ABOVE ;
731
- this . _setContentPosition ( visibleData , this . _renderingAbove ) ;
727
+ const widgetPosition = hoverData . showAtPosition ;
728
+ this . _positionPreference = this . _findRenderingPreference ( widgetHeight , widgetPosition ) ?? ContentWidgetPositionPreference . ABOVE ;
729
+ this . _setContentPosition ( hoverData , this . _positionPreference ) ;
732
730
733
731
// See https://github.com/microsoft/vscode/issues/140339
734
732
// TODO: Doing a second layout of the hover after force rendering the editor
735
733
this . onContentsChanged ( ) ;
736
- if ( visibleData . stoleFocus ) {
734
+ if ( hoverData . stoleFocus ) {
737
735
this . _hoverWidget . containerDomNode . focus ( ) ;
738
736
}
739
- visibleData . colorPicker ?. layout ( ) ;
737
+ hoverData . colorPicker ?. layout ( ) ;
740
738
}
741
739
742
740
public hide ( ) : void {
741
+ if ( ! this . _hoverData ) {
742
+ return ;
743
+ }
744
+ this . _setHoverData ( undefined ) ;
743
745
this . _resizableNode . maxSize = new dom . Dimension ( Infinity , Infinity ) ;
744
746
this . _resizableNode . clearSashHoverState ( ) ;
745
747
this . _editor . removeContentWidget ( this ) ;
746
- if ( this . _visibleData ) {
747
- const stoleFocus = this . _visibleData . stoleFocus ;
748
- this . _setVisibleData ( undefined ) ;
749
- this . _hoverFocusedKey . set ( false ) ;
750
- this . _editor . layoutContentWidget ( this ) ;
751
- if ( stoleFocus ) {
752
- this . _editor . focus ( ) ;
753
- }
748
+ this . _hoverFocusedKey . set ( false ) ;
749
+ this . _editor . layoutContentWidget ( this ) ;
750
+ if ( this . _hoverData . stoleFocus ) {
751
+ this . _editor . focus ( ) ;
754
752
}
755
753
}
756
754
@@ -760,8 +758,9 @@ export class ResizableHoverWidget extends MultiplePersistedSizeResizableContentW
760
758
const persistedSize = this . findPersistedSize ( ) ;
761
759
// Suppose a persisted size is defined
762
760
if ( persistedSize ) {
763
- width = Math . min ( this . _findAvailableSpaceHorizontally ( ) ?? Infinity , persistedSize . width - 2 * SASH_WIDTH_MINUS_BORDER ) ;
764
- height = Math . min ( this . _findAvailableSpaceVertically ( ) ?? Infinity , persistedSize . height - 2 * SASH_WIDTH_MINUS_BORDER ) ;
761
+ const totalBorderWidth = 2 * SASH_WIDTH_MINUS_BORDER ;
762
+ width = Math . min ( this . _findAvailableSpaceHorizontally ( ) ?? Infinity , persistedSize . width - totalBorderWidth ) ;
763
+ height = Math . min ( this . _findAvailableSpaceVertically ( ) ?? Infinity , persistedSize . height - totalBorderWidth ) ;
765
764
} else {
766
765
// Added because otherwise the initial size of the hover content is smaller than should be
767
766
const layoutInfo = this . _editor . getLayoutInfo ( ) ;
@@ -791,7 +790,8 @@ export class ResizableHoverWidget extends MultiplePersistedSizeResizableContentW
791
790
const containerDomNode = this . _hoverWidget . containerDomNode ;
792
791
const clientHeight = containerDomNode . clientHeight ;
793
792
const clientWidth = containerDomNode . clientWidth ;
794
- this . _resizableNode . layout ( clientHeight + 2 * SASH_WIDTH_MINUS_BORDER , clientWidth + 2 * SASH_WIDTH_MINUS_BORDER ) ;
793
+ const totalBorderWidth = 2 * SASH_WIDTH_MINUS_BORDER ;
794
+ this . _resizableNode . layout ( clientHeight + totalBorderWidth , clientWidth + totalBorderWidth ) ;
795
795
this . _setContainerAbsolutePosition ( SASH_WIDTH_MINUS_BORDER - 1 , SASH_WIDTH_MINUS_BORDER - 1 ) ;
796
796
if ( this . _hasHorizontalScrollbar ( ) ) {
797
797
this . _adjustContentsBottomPadding ( ) ;
0 commit comments