From e7085ef257f7421773a1d8592b3a51bd67ae596c Mon Sep 17 00:00:00 2001 From: Oscar Westra van Holthe - Kind Date: Thu, 5 Sep 2024 16:03:26 +0200 Subject: [PATCH] Use EDT when previewing quick fixes (fixes #177) --- .../SimpleAvroIdlQuickFixOnPsiElement.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/opwvhk/intellij/avro_idl/inspections/SimpleAvroIdlQuickFixOnPsiElement.java b/src/main/java/opwvhk/intellij/avro_idl/inspections/SimpleAvroIdlQuickFixOnPsiElement.java index 7b3230a..d0b8659 100644 --- a/src/main/java/opwvhk/intellij/avro_idl/inspections/SimpleAvroIdlQuickFixOnPsiElement.java +++ b/src/main/java/opwvhk/intellij/avro_idl/inspections/SimpleAvroIdlQuickFixOnPsiElement.java @@ -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; @@ -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) {