Skip to content

Commit

Permalink
Find/Replace overlay: remove search scope when leaving overlay #1919
Browse files Browse the repository at this point in the history
Replace the FocusListener with a ShellAdapter which will remove the
search scope as soon as the overlay is left.
The FocusListener didn't listen to the case where the focus is in the
search bar and the search bar is left (and the overlay is left
implicitly)

fixes #1919
  • Loading branch information
Maximilian Wittmer authored and HeikoKlare committed Jun 27, 2024
1 parent 9d6981f commit fc44255
Showing 1 changed file with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
Expand Down Expand Up @@ -226,10 +228,17 @@ public void controlResized(ControlEvent e) {
}
};

private FocusListener overlayFocusListener = FocusListener.focusLostAdapter(e -> {
findReplaceLogic.activate(SearchOptions.GLOBAL);
searchInSelectionButton.setSelection(false);
});
private ShellAdapter overlayDeactivationListener = new ShellAdapter() {
@Override
public void shellActivated(ShellEvent e) {
// Do nothing
}

@Override
public void shellDeactivated(ShellEvent e) {
removeSearchScope();
}
};

private PaintListener widgetMovementListener = __ -> positionToPart();

Expand Down Expand Up @@ -317,7 +326,7 @@ public int open() {
}
overlayOpen = true;
applyOverlayColors(backgroundToUse, true);
initFindStringFromSelection();
updateFromTargetSelection();

getShell().layout();
positionToPart();
Expand Down Expand Up @@ -361,7 +370,7 @@ private void applyOverlayColors(Color color, boolean tryToColorReplaceBar) {
}

private void unbindListeners() {
getShell().removeFocusListener(overlayFocusListener);
getShell().removeShellListener(overlayDeactivationListener);
if (targetPart != null && targetPart instanceof StatusTextEditor textEditor) {
Control targetWidget = textEditor.getSourceViewer().getTextWidget();
if (targetWidget != null) {
Expand All @@ -373,7 +382,7 @@ private void unbindListeners() {
}

private void bindListeners() {
getShell().addFocusListener(overlayFocusListener);
getShell().addShellListener(overlayDeactivationListener);
if (targetPart instanceof StatusTextEditor textEditor) {
Control targetWidget = textEditor.getSourceViewer().getTextWidget();

Expand Down Expand Up @@ -815,7 +824,7 @@ private void performSearch(boolean forward) {
findReplaceLogic.activate(SearchOptions.INCREMENTAL);
}

private void initFindStringFromSelection() {
private void updateFromTargetSelection() {
String initText = findReplaceLogic.getTarget().getSelectionText();
if (initText.isEmpty()) {
return;
Expand Down Expand Up @@ -863,4 +872,9 @@ private static boolean okayToUse(Widget widget) {
public void setPositionToTop(boolean shouldPositionOverlayOnTop) {
positionAtTop = shouldPositionOverlayOnTop;
}

private void removeSearchScope() {
findReplaceLogic.activate(SearchOptions.GLOBAL);
searchInSelectionButton.setSelection(false);
}
}

0 comments on commit fc44255

Please sign in to comment.