From e7a5dad12e8a48b36bfdcf09c03fac5d89071eb2 Mon Sep 17 00:00:00 2001 From: Traben Date: Sat, 27 Sep 2025 06:51:27 +1000 Subject: [PATCH] separate preprocessor block folding to allow folding each if/ifdef/elseif/else block separately --- .../editor/PreprocessorFolding.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/kotlin/org/polyfrost/intelliprocessor/editor/PreprocessorFolding.kt b/src/main/kotlin/org/polyfrost/intelliprocessor/editor/PreprocessorFolding.kt index 641fb82..2718090 100644 --- a/src/main/kotlin/org/polyfrost/intelliprocessor/editor/PreprocessorFolding.kt +++ b/src/main/kotlin/org/polyfrost/intelliprocessor/editor/PreprocessorFolding.kt @@ -42,6 +42,23 @@ class PreprocessorFolding : FoldingBuilderEx(), DumbAware { stack.addLast(directive) } + text.startsWith(directivePrefix + "else") || text.startsWith(directivePrefix + "elseif") -> { + val startDirective = stack.removeLastOrNull() + if (startDirective != null) { + val commentLine = document.getLineNumber(directive.textOffset) + if (commentLine > 0) { + val prevLineEnd = document.getLineEndOffset(commentLine - 1) + descriptors.add( + FoldingDescriptor( + startDirective, + TextRange(startDirective.textRange.startOffset, prevLineEnd) + ) + ) + stack.addLast(directive) + } + } + } + text.startsWith(directivePrefix + "endif") -> { val startDirective = stack.removeLastOrNull() if (startDirective != null) {