diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 8c92da159..27f270b20 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -15,6 +15,7 @@ This document provides a high-level view of the changes introduced by release. - Show error popup if a PDF file can't be written to disk (#1569) - Quoted strings now highlighted with a background in the editor even if they contain single or double quotes - Disable off-screen-rendering if IDE's setting for off-screen-rendering is disabled (#1575) +- Prevent exception when showing injected AsciiDoc content (#1576) === 0.41.9 diff --git a/src/main/java/org/asciidoc/intellij/psi/AbstractAsciiDocCodeBlock.java b/src/main/java/org/asciidoc/intellij/psi/AbstractAsciiDocCodeBlock.java index faa646cbf..0f5fb7c30 100644 --- a/src/main/java/org/asciidoc/intellij/psi/AbstractAsciiDocCodeBlock.java +++ b/src/main/java/org/asciidoc/intellij/psi/AbstractAsciiDocCodeBlock.java @@ -2,6 +2,8 @@ import com.intellij.lang.ASTNode; import com.intellij.navigation.ItemPresentation; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.AbstractElementManipulator; @@ -106,15 +108,17 @@ public String getLocationString() { @Override public boolean isValidHost() { - // must not use PsiTreeUtil.findChildOfType as it leads to exception - for (PsiElement e : this.getChildren()) { - // if there is a block macro (typically an include), disable highlighting for all of it - if (e instanceof AsciiDocBlockMacro) { - return false; + return ApplicationManager.getApplication().runReadAction((Computable) () -> { + // must not use PsiTreeUtil.findChildOfType as it leads to exception + for (PsiElement e : this.getChildren()) { + // if there is a block macro (typically an include), disable highlighting for all of it + if (e instanceof AsciiDocBlockMacro) { + return false; + } } - } - // check if there are i.e. non-matching elements - return !getContentTextRange().equals(TextRange.EMPTY_RANGE); + // check if there are i.e. non-matching elements + return !getContentTextRange().equals(TextRange.EMPTY_RANGE); + }); } /**