Skip to content

Commit 10b2b18

Browse files
committed
fix document format method
1 parent beb0aac commit 10b2b18

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

core/src/main/java/net/j4c0b3y/api/config/ConfigDocument.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,25 @@ public String format(String content) {
144144
List<String> formatted = new ArrayList<>();
145145
String[] lines = content.split("\n");
146146

147-
int previous = -1;
147+
int previousIndentation = -1;
148+
boolean previousComment = false;
148149

149150
for (int i = 0; i < lines.length; i++) {
150151
if (lines[i].isEmpty()) continue;
151152

152-
int current = StringUtils.getIndentation(lines[i]);
153+
int currentIndentation = StringUtils.getIndentation(lines[i]);
154+
boolean currentComment = lines[i].trim().startsWith("#");
153155

154-
if (current == 0 && previous > 0) {
156+
boolean comment = currentComment && !previousComment && previousIndentation >= currentIndentation;
157+
boolean section = currentIndentation == 0 && previousIndentation > 0 && !previousComment;
158+
159+
if (comment || section) {
155160
lines[i] = "\n" + lines[i];
156161
}
157162

158-
previous = current;
163+
previousIndentation = currentIndentation;
164+
previousComment = currentComment;
165+
159166
formatted.add(lines[i]);
160167
}
161168

0 commit comments

Comments
 (0)