Skip to content

Commit

Permalink
Prevent change-outside-of-command exception when creating a preview f…
Browse files Browse the repository at this point in the history
…or adding an ID to a section (#1577)
  • Loading branch information
ahus1 committed Mar 23, 2024
1 parent 2019f4c commit b4876e7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This document provides a high-level view of the changes introduced by release.
- 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)
- Prevent change-outside-of-command exception when creating a preview for adding an ID to a section (#1577)

=== 0.41.9

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

IntelliJ will interrupt threads for better interactivity.
The disadvantage is that this is also triggered when the developer debugs the plugin.
To disable this functionality find the action "`Disable ProcessCanceledException`" once the IDE has started.
To disable this functionality find the action "`Skip Window Deactivation Events`" ("`Disable ProcessCanceledException`" in 2023.1 and earlier) once the IDE has started.
Each restart will reset the settings.

To enable logging at debug and trace level the user (or developer) can change settings via menu:Help[Debug Log Settings] and enter (including the hash at the beginning) a logger name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,23 @@ public AsciiDocAddBlockIdToSection(PsiElement element) {

@Override
public @NotNull IntentionPreviewInfo generatePreview(@NotNull Project project, @NotNull ProblemDescriptor previewDescriptor) {
IntentionPreviewInfo intentionPreviewInfo = LocalQuickFix.super.generatePreview(project, previewDescriptor);
if (intentionPreviewInfo == IntentionPreviewInfo.EMPTY) {
PsiElement element = previewDescriptor.getPsiElement();
AsciiDocSection section = ((HasAnchorReference) previewDescriptor.getPsiElement()).resolveAnchorForSection();
if (section != null) {
if (section.getBlockId() == null) {
PsiElement firstChild = section.getFirstChild();
String id = section.getAutogeneratedId();
AsciiDocFileReference reference = ((HasAnchorReference) element).getAnchorReference();
if (reference != null && !reference.isPossibleRefText()) {
id = reference.getRangeInElement().substring(element.getText());
}
String origText = section.getContainingFile().getText();
StringBuilder newText = new StringBuilder(origText);
newText.insert(firstChild.getTextOffset(), "[#" + id + "]\n");
intentionPreviewInfo =
new IntentionPreviewInfo.CustomDiff(AsciiDocFileType.INSTANCE, section.getContainingFile().getName(), origText, newText.toString(), true);
PsiElement element = previewDescriptor.getPsiElement();
AsciiDocSection section = ((HasAnchorReference) previewDescriptor.getPsiElement()).resolveAnchorForSection();
if (section != null) {
if (section.getBlockId() == null) {
PsiElement firstChild = section.getFirstChild();
String id = section.getAutogeneratedId();
AsciiDocFileReference reference = ((HasAnchorReference) element).getAnchorReference();
if (reference != null && !reference.isPossibleRefText()) {
id = reference.getRangeInElement().substring(element.getText());
}
String origText = section.getContainingFile().getText();
StringBuilder newText = new StringBuilder(origText);
newText.insert(firstChild.getTextOffset(), "[#" + id + "]\n");
return new IntentionPreviewInfo.CustomDiff(AsciiDocFileType.INSTANCE, section.getContainingFile().getName(), origText, newText.toString(), true);
}
}
return intentionPreviewInfo;
return IntentionPreviewInfo.EMPTY;
}

@Override
Expand Down

0 comments on commit b4876e7

Please sign in to comment.