@@ -751,7 +751,7 @@ private void enableReplaceTools(boolean enable) {
751751 replaceTools .setVisible (enable );
752752 }
753753
754- private int getIdealDialogWidth (Rectangle targetBounds ) {
754+ private int getIdealOverlayWidth (Rectangle targetBounds ) {
755755 int idealOverlayWidth = calculateOverlayWidthWithToolbars (IDEAL_WIDTH_TEXT );
756756 int minimumOverlayWidth = Math .min (calculateOverlayWidthWithoutToolbars (MINIMAL_WIDTH_TEXT ),
757757 (int ) (targetBounds .width * WORST_CASE_RATIO_EDITOR_TO_OVERLAY ));
@@ -799,20 +799,6 @@ private int getTextWidthInSearchBar(String input) {
799799 return textWidth ;
800800 }
801801
802- private Point getNewPosition (Widget targetTextWidget , Point targetOrigin , Rectangle targetBounds ,
803- Point expectedSize ) {
804- Point verticalScrollBarSize = ((Scrollable ) targetTextWidget ).getVerticalBar ().getSize ();
805- Point horizontalScrollBarSize = ((Scrollable ) targetTextWidget ).getHorizontalBar ().getSize ();
806-
807- int newX = targetOrigin .x + targetBounds .width - expectedSize .x - verticalScrollBarSize .x
808- - ((StyledText ) targetTextWidget ).getRightMargin ();
809- int newY = targetOrigin .y ;
810- if (!positionAtTop ) {
811- newY += targetBounds .height - expectedSize .y - horizontalScrollBarSize .y ;
812- }
813- return new Point (newX , newY );
814- }
815-
816802 /**
817803 * When making the text-bar 100% small and then regrowing it, we want the text
818804 * to start at the first character again.
@@ -828,30 +814,66 @@ private void repositionTextSelection() {
828814
829815 private void positionToPart () {
830816 getShell ().requestLayout ();
831- if (!(targetPart instanceof StatusTextEditor )) {
817+ if (!(targetPart instanceof StatusTextEditor textEditor )) {
832818 return ;
833819 }
834820
835- StatusTextEditor textEditor = (StatusTextEditor ) targetPart ;
836821 Control targetWidget = textEditor .getAdapter (ITextViewer .class ).getTextWidget ();
837822 if (!okayToUse (targetWidget )) {
838823 this .close ();
839824 return ;
840825 }
841826
842- Point targetOrigin = targetWidget .toDisplay (0 , 0 );
843- Rectangle targetBounds = targetWidget .getBounds ();
827+ Rectangle targetControlBounds = calculateAbsoluteControlBounds (targetWidget );
828+ Rectangle overlayBounds = calculateDesiredOverlayBounds (targetControlBounds );
829+ updatePosition (overlayBounds );
830+ configureDisplayedWidgetsForWidth (overlayBounds .width );
831+ updateVisibility (targetControlBounds , overlayBounds );
844832
845- int newWidth = getIdealDialogWidth (targetBounds );
846- int newHeight = container .computeSize (SWT .DEFAULT , SWT .DEFAULT ).y ;
833+ repositionTextSelection ();
834+ }
835+
836+ private Rectangle calculateAbsoluteControlBounds (Control control ) {
837+ Rectangle localControlBounds = control .getBounds ();
838+ int width = localControlBounds .width ;
839+ int height = localControlBounds .height ;
840+ if (control instanceof Scrollable scrollable ) {
841+ width -= scrollable .getVerticalBar ().getSize ().x ;
842+ height -= scrollable .getHorizontalBar ().getSize ().y ;
843+ }
844+ if (control instanceof StyledText styledText ) {
845+ width -= styledText .getRightMargin ();
846+ }
847+ Point absoluteControlPosition = control .toDisplay (0 , 0 );
848+ return new Rectangle (absoluteControlPosition .x , absoluteControlPosition .y , width , height );
849+ }
847850
848- Point newPosition = getNewPosition (targetWidget , targetOrigin , targetBounds , new Point (newWidth , newHeight ));
851+ private Rectangle calculateDesiredOverlayBounds (Rectangle targetControlBounds ) {
852+ int width = getIdealOverlayWidth (targetControlBounds );
853+ int height = container .computeSize (SWT .DEFAULT , SWT .DEFAULT ).y ;
849854
850- getShell ().setSize (new Point (newWidth , newHeight ));
851- getShell ().setLocation (newPosition );
855+ int x = targetControlBounds .x + targetControlBounds .width - width ;
856+ int y = targetControlBounds .y ;
857+ if (!positionAtTop ) {
858+ y += targetControlBounds .height - height ;
859+ }
860+
861+ return new Rectangle (x , y , width , height );
862+ }
863+
864+ private void updatePosition (Rectangle overlayBounds ) {
865+ getShell ().setSize (new Point (overlayBounds .width , overlayBounds .height ));
866+ getShell ().setLocation (new Point (overlayBounds .x , overlayBounds .y ));
852867 getShell ().layout (true );
853- configureDisplayedWidgetsForWidth (newWidth );
854- repositionTextSelection ();
868+ }
869+
870+ private void updateVisibility (Rectangle targetControlBounds , Rectangle overlayBounds ) {
871+ if (positionAtTop ) {
872+ getShell ().setVisible (
873+ overlayBounds .y + overlayBounds .height <= targetControlBounds .y + targetControlBounds .height );
874+ } else {
875+ getShell ().setVisible (overlayBounds .y >= targetControlBounds .y );
876+ }
855877 }
856878
857879 private String getFindString () {
0 commit comments