Skip to content

Commit fc44255

Browse files
Maximilian WittmerHeikoKlare
authored andcommitted
Find/Replace overlay: remove search scope when leaving overlay eclipse-platform#1919
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 eclipse-platform#1919
1 parent 9d6981f commit fc44255

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceOverlay.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.eclipse.swt.events.KeyListener;
2727
import org.eclipse.swt.events.PaintListener;
2828
import org.eclipse.swt.events.SelectionListener;
29+
import org.eclipse.swt.events.ShellAdapter;
30+
import org.eclipse.swt.events.ShellEvent;
2931
import org.eclipse.swt.graphics.Color;
3032
import org.eclipse.swt.graphics.GC;
3133
import org.eclipse.swt.graphics.Point;
@@ -226,10 +228,17 @@ public void controlResized(ControlEvent e) {
226228
}
227229
};
228230

229-
private FocusListener overlayFocusListener = FocusListener.focusLostAdapter(e -> {
230-
findReplaceLogic.activate(SearchOptions.GLOBAL);
231-
searchInSelectionButton.setSelection(false);
232-
});
231+
private ShellAdapter overlayDeactivationListener = new ShellAdapter() {
232+
@Override
233+
public void shellActivated(ShellEvent e) {
234+
// Do nothing
235+
}
236+
237+
@Override
238+
public void shellDeactivated(ShellEvent e) {
239+
removeSearchScope();
240+
}
241+
};
233242

234243
private PaintListener widgetMovementListener = __ -> positionToPart();
235244

@@ -317,7 +326,7 @@ public int open() {
317326
}
318327
overlayOpen = true;
319328
applyOverlayColors(backgroundToUse, true);
320-
initFindStringFromSelection();
329+
updateFromTargetSelection();
321330

322331
getShell().layout();
323332
positionToPart();
@@ -361,7 +370,7 @@ private void applyOverlayColors(Color color, boolean tryToColorReplaceBar) {
361370
}
362371

363372
private void unbindListeners() {
364-
getShell().removeFocusListener(overlayFocusListener);
373+
getShell().removeShellListener(overlayDeactivationListener);
365374
if (targetPart != null && targetPart instanceof StatusTextEditor textEditor) {
366375
Control targetWidget = textEditor.getSourceViewer().getTextWidget();
367376
if (targetWidget != null) {
@@ -373,7 +382,7 @@ private void unbindListeners() {
373382
}
374383

375384
private void bindListeners() {
376-
getShell().addFocusListener(overlayFocusListener);
385+
getShell().addShellListener(overlayDeactivationListener);
377386
if (targetPart instanceof StatusTextEditor textEditor) {
378387
Control targetWidget = textEditor.getSourceViewer().getTextWidget();
379388

@@ -815,7 +824,7 @@ private void performSearch(boolean forward) {
815824
findReplaceLogic.activate(SearchOptions.INCREMENTAL);
816825
}
817826

818-
private void initFindStringFromSelection() {
827+
private void updateFromTargetSelection() {
819828
String initText = findReplaceLogic.getTarget().getSelectionText();
820829
if (initText.isEmpty()) {
821830
return;
@@ -863,4 +872,9 @@ private static boolean okayToUse(Widget widget) {
863872
public void setPositionToTop(boolean shouldPositionOverlayOnTop) {
864873
positionAtTop = shouldPositionOverlayOnTop;
865874
}
875+
876+
private void removeSearchScope() {
877+
findReplaceLogic.activate(SearchOptions.GLOBAL);
878+
searchInSelectionButton.setSelection(false);
879+
}
866880
}

0 commit comments

Comments
 (0)