diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java index 8fc2fa7a917..434f569194b 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java @@ -143,10 +143,25 @@ private final class KeyboardShortcuts { private Color normalTextForegroundColor; private boolean positionAtTop = true; private boolean isTargetVisible = true; + private final Runnable onParentShellChange; - public FindReplaceOverlay(Shell parent, IWorkbenchPart part, IFindReplaceTarget target) { + /** + * Constructs the Overlay. + * + * @param parent the parent shell + * @param part the {@code ViewPart} which is targeted by the + * overlay + * @param target the {@code FindReplaceTarget} used as target for + * performing the find/replace operations + * @param onParentShellChange if the targeted ViewPart is moved to another + * shell, the overlay closes itself and calls this + * callback to notify the client. + */ + public FindReplaceOverlay(Shell parent, IWorkbenchPart part, IFindReplaceTarget target, + Runnable onParentShellChange) { super(parent); createFindReplaceLogic(target); + this.onParentShellChange = onParentShellChange; setShellStyle(SWT.MODELESS); setBlockOnOpen(false); @@ -841,6 +856,7 @@ private void repositionTextSelection() { private void updatePlacementAndVisibility() { if (isInvalidTargetShell()) { + getShell().getDisplay().asyncExec(onParentShellChange); close(); return; } diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceAction.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceAction.java index 7de6e3c2106..7c12430ca20 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceAction.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/FindReplaceAction.java @@ -420,7 +420,11 @@ private void showOverlayInEditor() { } else { shellToUse = fShell; } - overlay = new FindReplaceOverlay(shellToUse, fWorkbenchPart, fTarget); + overlay = new FindReplaceOverlay(shellToUse, fWorkbenchPart, fTarget, () -> { + overlay = null; + showOverlayInEditor(); + fWorkbenchPart.setFocus(); + }); hookDialogPreferenceListener(); FindReplaceOverlayFirstTimePopup.displayPopupIfNotAlreadyShown(shellToUse);