From d121c1e4af4961686b6fa920a74364e985f78213 Mon Sep 17 00:00:00 2001 From: Maximilian Wittmer Date: Mon, 10 Jun 2024 11:05:01 +0200 Subject: [PATCH] Find/Replace overlay: handle the case when moving editor between windows When moving the targeted editor between different windows, the overlay is closed to allow a retargetting. fixes #1945 --- .../overlay/FindReplaceOverlay.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 b7291beb7dc..135e8e67e48 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 @@ -882,6 +882,15 @@ private void updatePlacementAndVisibility() { getShell().setVisible(false); return; } + if (isInvalidTargetShell()) { + getShell().getDisplay().syncExec(() -> { + close(); + setParentShell(targetPart.getSite().getShell()); + open(); + targetPart.setFocus(); + }); + return; + } getShell().requestLayout(); if (!(targetPart instanceof StatusTextEditor textEditor)) { return; @@ -902,6 +911,17 @@ private void updatePlacementAndVisibility() { 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;