Skip to content

Commit cac3db1

Browse files
authored
Merge pull request #23 from Traben-0/main
enhance preprocessor block folding so each if/ifdef/elseif/else block can fold separately
2 parents 11cfdd8 + e7a5dad commit cac3db1

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/main/kotlin/org/polyfrost/intelliprocessor/editor/PreprocessorFolding.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ class PreprocessorFolding : FoldingBuilderEx(), DumbAware {
4242
stack.addLast(directive)
4343
}
4444

45+
text.startsWith(directivePrefix + "else") || text.startsWith(directivePrefix + "elseif") -> {
46+
val startDirective = stack.removeLastOrNull()
47+
if (startDirective != null) {
48+
val commentLine = document.getLineNumber(directive.textOffset)
49+
if (commentLine > 0) {
50+
val prevLineEnd = document.getLineEndOffset(commentLine - 1)
51+
descriptors.add(
52+
FoldingDescriptor(
53+
startDirective,
54+
TextRange(startDirective.textRange.startOffset, prevLineEnd)
55+
)
56+
)
57+
stack.addLast(directive)
58+
}
59+
}
60+
}
61+
4562
text.startsWith(directivePrefix + "endif") -> {
4663
val startDirective = stack.removeLastOrNull()
4764
if (startDirective != null) {

0 commit comments

Comments
 (0)