Skip to content

Commit

Permalink
Find/Replace overlay: fix Ctrl+F6 crash on Linux
Browse files Browse the repository at this point in the history
Avoid being stuck in an event loop by reacting asynchronously to part
activation events.
Additionally, manually give focus to the editor part after switching.
This behavior is default on windows but not consistent on Linux.

fixes #1951
  • Loading branch information
Maximilian Wittmer authored and Maximilian Wittmer committed Jun 17, 2024
1 parent 8af8b3f commit b85fd61
Showing 1 changed file with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,32 @@ public void controlResized(ControlEvent e) {
private IPartListener partListener = new IPartListener() {
@Override
public void partActivated(IWorkbenchPart part) {
if (getShell() != null) {
getShell().setVisible(isPartCurrentlyDisplayedInPartSash());
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
adaptToPartActivationChange();
}
});
}

@Override
public void partDeactivated(IWorkbenchPart part) {
// Do nothing
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
adaptToPartActivationChange();
}
});
}

@Override
public void partBroughtToTop(IWorkbenchPart part) {
if (getShell() != null) {
getShell().setVisible(isPartCurrentlyDisplayedInPartSash());
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
adaptToPartActivationChange();
}
});
}

@Override
Expand All @@ -264,6 +275,34 @@ public void partOpened(IWorkbenchPart part) {
}
};

private void adaptToPartActivationChange() {
if (getShell() == null || targetPart.getSite().getShell() == null) {
return;
}

getShell().setVisible(isPartCurrentlyDisplayedInPartSash());

targetPart.getSite().getShell().setActive();
targetPart.getSite().getPart().setFocus();

if (!(targetPart instanceof StatusTextEditor)) {
return;
}

StatusTextEditor textEditor = (StatusTextEditor) targetPart;
Control targetWidget = textEditor.getSourceViewer().getTextWidget();

Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (targetPart.getSite().getShell() == null) {
return;
}
targetWidget.forceFocus();
}
});
}

private boolean isPartCurrentlyDisplayedInPartSash() {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

Expand Down

0 comments on commit b85fd61

Please sign in to comment.