Skip to content

Commit

Permalink
Prevent exception when showing injected AsciiDoc content (#1576)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahus1 committed Mar 23, 2024
1 parent c4e45d6 commit 2019f4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Boolean>) () -> {
// 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);
});
}

/**
Expand Down

0 comments on commit 2019f4c

Please sign in to comment.