Skip to content

Commit

Permalink
Find/Replace overlay: handle the case when moving editor between windows
Browse files Browse the repository at this point in the history
When moving the targeted editor between different windows, the overlay
is closed to allow a retargetting.

fixes #1945
  • Loading branch information
Wittmaxi committed Jul 16, 2024
1 parent 224ee6f commit 1f1092b
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ public FindReplaceOverlay(Shell parent, IWorkbenchPart part, IFindReplaceTarget
setShellStyle(SWT.MODELESS);
setBlockOnOpen(false);
targetPart = part;

}

@Override
Expand Down Expand Up @@ -840,9 +839,17 @@ private void repositionTextSelection() {
}

private void updatePlacementAndVisibility() {
if (isInvalidTargetShell()) {
getShell().getDisplay().syncExec(() -> {
close();
setParentShell(targetPart.getSite().getShell());
open();
targetPart.setFocus();
});
return;
}
if (!isTargetVisible) {
getShell().setVisible(false);
return;
}
getShell().requestLayout();
if (!(targetPart instanceof StatusTextEditor textEditor)) {
Expand All @@ -864,6 +871,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;
Expand Down

0 comments on commit 1f1092b

Please sign in to comment.