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 80c171dd62e..b122245cece 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 @@ -813,6 +813,10 @@ private void repositionTextSelection() { } private void positionToPart() { + if (isInvalidTargetShell()) { + close(); + return; + } getShell().requestLayout(); if (!(targetPart instanceof StatusTextEditor textEditor)) { return; @@ -833,6 +837,17 @@ private void positionToPart() { repositionTextSelection(); } + private boolean isInvalidTargetPart() { + return targetPart == null || targetPart.getSite() == null || targetPart.getSite().getShell() == null; + } + + private boolean isInvalidTargetShell() { + if (isInvalidTargetPart()) { + return false; + } + return getShell() == null || !targetPart.getSite().getShell().equals(getShell().getParent()); + } + private Rectangle calculateAbsoluteControlBounds(Control control) { Rectangle localControlBounds = control.getBounds(); int width = localControlBounds.width; 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..f9973335b80 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 @@ -412,7 +412,7 @@ private void showDialog() { } private void showOverlayInEditor() { - if (overlay == null) { + if (shouldCreateNewOverlay()) { Shell shellToUse = null; if (fShell == null) { @@ -431,6 +431,10 @@ private void showOverlayInEditor() { overlay.getShell().addDisposeListener(__ -> removeDialogPreferenceListener()); } + private boolean shouldCreateNewOverlay() { + return overlay == null || overlay.getShell() == null || overlay.getShell().isDisposed(); + } + @Override public void update() {