From 41e4727ae8fcba6831781c14e655c9d0f7308183 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 | 22 +++++++++++++++++++ .../ui/texteditor/FindReplaceAction.java | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) 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..8c4a4f2c316 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 @@ -353,6 +353,10 @@ public boolean close() { @Override public int open() { + super.open(); + if (!okayToUse(getShell())) { + return Window.CANCEL; + } int returnCode = Window.OK; if (!overlayOpen) { returnCode = super.open(); @@ -813,6 +817,10 @@ private void repositionTextSelection() { } private void positionToPart() { + if (isInvalidShell()) { + close(); + return; + } getShell().requestLayout(); if (!(targetPart instanceof StatusTextEditor textEditor)) { return; @@ -833,6 +841,17 @@ private void positionToPart() { repositionTextSelection(); } + private boolean isInvalidTargetPart() { + return targetPart == null || targetPart.getSite() == null || targetPart.getSite().getShell() == null; + } + + private boolean isInvalidShell() { + 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; @@ -954,4 +973,7 @@ private void removeSearchScope() { findReplaceLogic.activate(SearchOptions.GLOBAL); searchInSelectionButton.setSelection(false); } + public boolean isOverlayOpen() { + return overlayOpen; + } } \ No newline at end of file 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..b5c8030bed5 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 (overlay == null || !overlay.isOverlayOpen()) { Shell shellToUse = null; if (fShell == null) {