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 HeikoKlare committed Jul 4, 2024
1 parent d67d6c7 commit f8acd2d
Showing 1 changed file with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,17 @@ public void shellDeactivated(ShellEvent e) {
private IPartListener partListener = new IPartListener() {
@Override
public void partActivated(IWorkbenchPart part) {
if (getShell() != null) {
getShell().setVisible(isPartCurrentlyDisplayedInPartSash());
}
getShell().getDisplay().asyncExec(this::adaptToPartActivationChange);
}

@Override
public void partDeactivated(IWorkbenchPart part) {
// Do nothing
getShell().getDisplay().asyncExec(this::adaptToPartActivationChange);
}

@Override
public void partBroughtToTop(IWorkbenchPart part) {
if (getShell() != null) {
getShell().setVisible(isPartCurrentlyDisplayedInPartSash());
}
getShell().getDisplay().asyncExec(this::adaptToPartActivationChange);
}

@Override
Expand All @@ -273,6 +269,35 @@ public void partClosed(IWorkbenchPart part) {
public void partOpened(IWorkbenchPart part) {
// Do nothing
}

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

boolean isOverlayVisible = isPartCurrentlyDisplayedInPartSash();

getShell().setVisible(isOverlayVisible);

if (isOverlayVisible) {
targetPart.getSite().getShell().setActive();
targetPart.setFocus();
getShell().getDisplay().asyncExec(this::focusTargetWidget);
}
}

private void focusTargetWidget() {
if (getShell() == null || targetPart.getSite().getPart() == null) {
return;
}
if (!(targetPart instanceof StatusTextEditor)) {
return;
}
StatusTextEditor textEditor = (StatusTextEditor) targetPart;
Control targetWidget = textEditor.getAdapter(ITextViewer.class).getTextWidget();

targetWidget.forceFocus();
}
};

private boolean isPartCurrentlyDisplayedInPartSash() {
Expand Down

0 comments on commit f8acd2d

Please sign in to comment.