Skip to content

Commit

Permalink
Use EDT when previewing quick fixes (fixes #177)
Browse files Browse the repository at this point in the history
  • Loading branch information
opwvhk committed Sep 5, 2024
1 parent 261e067 commit e7085ef
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.LogicalPosition;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.editor.impl.ImaginaryEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
Expand Down Expand Up @@ -54,20 +55,17 @@ public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file, @Not
return isAvailable(project, file, (E) startElement);
}

@Override
@SuppressWarnings("unchecked")
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement,
@NotNull PsiElement endElement) {
CommandProcessor.getInstance().executeCommand(project,
() -> invoke(project, file, (Editor) null, (E) startElement), text, null);
}

@Override
@SuppressWarnings("unchecked")
public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable Editor editor,
@NotNull PsiElement startElement, @NotNull PsiElement endElement) {
CommandProcessor.getInstance().executeCommand(project,
() -> invoke(project, file, editor, (E) startElement), text, null);
Runnable action = () -> invoke(project, file, editor, (E) startElement);
if (editor instanceof ImaginaryEditor) {
// We're generating a preview: stay on the EDT (do not switch to a write thread)
action.run();
} else {
CommandProcessor.getInstance().executeCommand(project, action, text, null);
}
}

protected void selectElement(Editor editor, @NotNull PsiElement element) {
Expand Down

0 comments on commit e7085ef

Please sign in to comment.