Skip to content

Commit

Permalink
Workaround for EDT error message when reopening a project (#1424)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahus1 committed Aug 29, 2023
1 parent f20ce69 commit cc4a22e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This document provides a high-level view of the changes introduced by release.

- Fix class cast exception when parsing Antora information (#1422)
- Fix regex problem when `idseparator` contains regex special characters (#1423)
- Workaround for EDT error message when reopening a project (#1424)

=== 0.39.3

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.asciidoc.intellij.ui;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileEditor.AsyncFileEditorProvider;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorPolicy;
Expand All @@ -12,6 +13,8 @@
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.atomic.AtomicReference;

public abstract class SplitTextEditorProvider implements AsyncFileEditorProvider, DumbAware {

private static final String FIRST_EDITOR = "first_editor";
Expand Down Expand Up @@ -58,8 +61,19 @@ public Builder createEditorAsync(@NotNull final Project project, @NotNull final

return new Builder() {
@Override
public FileEditor build() {
return createSplitEditor(firstBuilder.build(), secondBuilder.build());
public @NotNull FileEditor build() {
if (!ApplicationManager.getApplication().isDispatchThread()) {
// FileEditorManagerImpl$dumbModeFinished$fileToNewProviders will call this in a background thread
// EditorImpl wants to be called from EDT only, let's switch to EDT for this.
// This is a known problem: https://youtrack.jetbrains.com/issue/IDEA-318259 in 2023.2 and will be fixed in 2023.3
AtomicReference<FileEditor> editor = new AtomicReference<>();
ApplicationManager.getApplication().invokeAndWait(() -> {
editor.set(createSplitEditor(firstBuilder.build(), secondBuilder.build()));
});
return editor.get();
} else {
return createSplitEditor(firstBuilder.build(), secondBuilder.build());
}
}
};
}
Expand Down

0 comments on commit cc4a22e

Please sign in to comment.