Skip to content

Commit

Permalink
When creating a missing file in an Antora component, put it in the co…
Browse files Browse the repository at this point in the history
…rrect family folder
  • Loading branch information
ahus1 committed Aug 9, 2024
1 parent 2ace7df commit 1c8e958
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This document provides a high-level view of the changes introduced by release.
- Bump org.asciidoctor:asciidoctorj-diagram from 2.3.0 to 2.3.1 (#1639)
- Bump org.asciidoctor:asciidoctorj-diagram-plantuml from 1.2024.3 to 1.2024.5 (#1638)
- Don't show an error in the editor if an include doesn't find the Antora component (#1660)
- When creating a missing file in an Antora component, put it in the correct family folder

=== 0.42.2

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/asciidoc/intellij/psi/AsciiDocFileReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ public boolean canBeCreated() {
if (resolved.size() == 1) {
PsiElement baseElement = resolved.get(0).getElement();
if (baseElement instanceof PsiDirectory) {
if (isAntora && AsciiDocUtil.ANTORA_PREFIX_PATTERN.matcher(base).matches()) {
if (macroName.equals("image") || macroName.equals("video") || macroName.equals("audio")) {
PsiDirectory images = ((PsiDirectory) baseElement).findSubdirectory("images");
if (images == null) {
images = ((PsiDirectory) baseElement).createSubdirectory("images");
}
baseElement = images;
} else if (macroName.equals("xref") || macroName.equals("xref-attr") || macroName.equals("include")) {
PsiDirectory pages = ((PsiDirectory) baseElement).findSubdirectory("pages");
if (pages == null) {
pages = ((PsiDirectory) baseElement).createSubdirectory("pages");
}
baseElement = pages;
}
}
PsiDirectory parent = (PsiDirectory) baseElement;
String name = AsciiDocUtil.resolveAttributes(root, key);
if (name != null) {
Expand Down

0 comments on commit 1c8e958

Please sign in to comment.