Skip to content

Commit e786511

Browse files
committed
Properly update find/replace overlay size and displayed widgets #2006
Currently, the widgets in the find/replace overlay (search options, replace expand bar) are not always properly updated on size changes of the target editor. This is complicated by the implementation mixing up the calculation of the overlay size and the calculations to determine which widgets are displayed, which also leads to the missing updates the UI upon certain events requiring the resizing of the overlay. With this change, the calculations for the overlay size and the determination of the displayed widgets are separated. This also makes a template string for a "compromise text length" obsolete. It also removes the "size gap" between the minimal width of the overlay with the replace expansion bar, taking up 70% of the editor width, and the size of the width of the overlay without the replace expansion bar, taking up 95% of the editor width. Fixes #2006
1 parent 44dc49e commit e786511

File tree

1 file changed

+40
-27
lines changed
  • bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay

1 file changed

+40
-27
lines changed

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ public class FindReplaceOverlay extends Dialog {
7474
private static final String REPLACE_BAR_OPEN_DIALOG_SETTING = "replaceBarOpen"; //$NON-NLS-1$
7575
private static final double WORST_CASE_RATIO_EDITOR_TO_OVERLAY = 0.95;
7676
private static final double BIG_WIDTH_RATIO_EDITOR_TO_OVERLAY = 0.7;
77-
private static final String MINIMAL_WIDTH_TEXT = "THIS TEXT "; //$NON-NLS-1$
78-
private static final String COMPROMISE_WIDTH_TEXT = "THIS TEXT HAS A REASONABLE"; //$NON-NLS-1$
77+
private static final String MINIMAL_WIDTH_TEXT = "THIS TEXT IS SHORT "; //$NON-NLS-1$
7978
private static final String IDEAL_WIDTH_TEXT = "THIS TEXT HAS A REASONABLE LENGTH FOR SEARCHING"; //$NON-NLS-1$
8079
private FindReplaceLogic findReplaceLogic;
8180
private IWorkbenchPart targetPart;
@@ -746,37 +745,51 @@ private void enableReplaceTools(boolean enable) {
746745
}
747746

748747
private int getIdealDialogWidth(Rectangle targetBounds) {
748+
int idealOverlayWidth = calculateOverlayWidthWithToolbars(IDEAL_WIDTH_TEXT);
749+
int minimumOverlayWidth = Math.min(calculateOverlayWidthWithoutToolbars(MINIMAL_WIDTH_TEXT),
750+
(int) (targetBounds.width * WORST_CASE_RATIO_EDITOR_TO_OVERLAY));
751+
int maximumOverlayWidth = (int) (targetBounds.width * BIG_WIDTH_RATIO_EDITOR_TO_OVERLAY);
752+
753+
int overlayWidth = idealOverlayWidth;
754+
if (overlayWidth > maximumOverlayWidth) {
755+
overlayWidth = maximumOverlayWidth;
756+
}
757+
if (overlayWidth < minimumOverlayWidth) {
758+
overlayWidth = minimumOverlayWidth;
759+
}
760+
761+
return overlayWidth;
762+
}
763+
764+
private void configureDisplayedWidgetsForWidth(int overlayWidth) {
765+
int minimumWidthWithToolbars = calculateOverlayWidthWithoutToolbars(IDEAL_WIDTH_TEXT);
766+
int minimumWidthWithReplaceToggle = calculateOverlayWidthWithoutToolbars(MINIMAL_WIDTH_TEXT);
767+
enableSearchTools(overlayWidth >= minimumWidthWithToolbars);
768+
enableReplaceTools(overlayWidth >= minimumWidthWithToolbars);
769+
enableReplaceToggle(overlayWidth >= minimumWidthWithReplaceToggle);
770+
}
771+
772+
private int calculateOverlayWidthWithToolbars(String searchInput) {
773+
int toolbarWidth = searchTools.getSize().x;
774+
return calculateOverlayWidthWithoutToolbars(searchInput) + toolbarWidth;
775+
}
776+
777+
private int calculateOverlayWidthWithoutToolbars(String searchInput) {
749778
int replaceToggleWidth = 0;
750779
if (okayToUse(replaceToggle)) {
751780
replaceToggleWidth = replaceToggle.getBounds().width;
752781
}
753-
int toolBarWidth = searchTools.getSize().x + closeTools.getSize().x;
782+
int closeButtonWidth = closeTools.getSize().x;
783+
int searchInputWidth = getTextWidthInSearchBar(searchInput);
784+
return replaceToggleWidth + closeButtonWidth + searchInputWidth;
785+
}
786+
787+
private int getTextWidthInSearchBar(String input) {
754788
GC gc = new GC(searchBar);
755789
gc.setFont(searchBar.getFont());
756-
int idealWidth = gc.stringExtent(IDEAL_WIDTH_TEXT).x; // $NON-NLS-1$
757-
int idealCompromiseWidth = gc.stringExtent(COMPROMISE_WIDTH_TEXT).x; // $NON-NLS-1$
758-
int worstCompromiseWidth = gc.stringExtent(MINIMAL_WIDTH_TEXT).x; // $NON-NLS-1$
790+
int textWidth = gc.stringExtent(input).x; // $NON-NLS-1$
759791
gc.dispose();
760-
761-
int newWidth = idealWidth + toolBarWidth + replaceToggleWidth;
762-
if (newWidth > targetBounds.width * BIG_WIDTH_RATIO_EDITOR_TO_OVERLAY) {
763-
newWidth = (int) (targetBounds.width * BIG_WIDTH_RATIO_EDITOR_TO_OVERLAY);
764-
enableSearchTools(true);
765-
enableReplaceTools(true);
766-
enableReplaceToggle(true);
767-
}
768-
if (newWidth < idealCompromiseWidth + toolBarWidth) {
769-
enableSearchTools(false);
770-
enableReplaceTools(false);
771-
enableReplaceToggle(true);
772-
}
773-
if (newWidth < worstCompromiseWidth + toolBarWidth) {
774-
newWidth = (int) (targetBounds.width * WORST_CASE_RATIO_EDITOR_TO_OVERLAY);
775-
enableReplaceToggle(false);
776-
enableSearchTools(false);
777-
enableReplaceTools(false);
778-
}
779-
return newWidth;
792+
return textWidth;
780793
}
781794

782795
private Point getNewPosition(Widget targetTextWidget, Point targetOrigin, Rectangle targetBounds,
@@ -830,7 +843,7 @@ private void positionToPart() {
830843
getShell().setSize(new Point(newWidth, newHeight));
831844
getShell().setLocation(newPosition);
832845
getShell().layout(true);
833-
846+
configureDisplayedWidgetsForWidth(newWidth);
834847
repositionTextSelection();
835848
}
836849

0 commit comments

Comments
 (0)