2626import org .eclipse .swt .events .KeyListener ;
2727import org .eclipse .swt .events .PaintListener ;
2828import org .eclipse .swt .events .SelectionListener ;
29+ import org .eclipse .swt .events .ShellAdapter ;
30+ import org .eclipse .swt .events .ShellEvent ;
2931import org .eclipse .swt .graphics .Color ;
3032import org .eclipse .swt .graphics .GC ;
3133import 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