From 0a3f84708d653aff314f83b069b06db0954d5702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Tue, 9 Dec 2025 21:43:46 -0300 Subject: [PATCH] Fix in FoldRangeService::findFoldingRangesMarkdown --- src/eepp/ui/doc/foldrangeservice.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/eepp/ui/doc/foldrangeservice.cpp b/src/eepp/ui/doc/foldrangeservice.cpp index 32b2c223a..b77eaea0a 100644 --- a/src/eepp/ui/doc/foldrangeservice.cpp +++ b/src/eepp/ui/doc/foldrangeservice.cpp @@ -102,6 +102,7 @@ static std::vector findFoldingRangesIndentation( TextDocument* doc ) } static std::vector findFoldingRangesMarkdown( TextDocument* doc ) { + static const String codeFence( "```" ); Clock c; // For performance logging, consistent with existing functions std::vector regions; auto lineCount = doc->linesCount(); @@ -138,9 +139,16 @@ static std::vector findFoldingRangesMarkdown( TextDocument* doc ) { // Continue to next line if still in code block } else { if ( String::startsWith( trimmed, "```" ) ) { - // Start a new code block - inCodeBlock = true; - codeBlockStart = static_cast( lineIdx ); + // Check if the line contains a closing ``` on the same line. + // We search starting from index 3 (after the opening ```). + bool isSingleLineBlock = + trimmed.size() > 3 && trimmed.find( codeFence.view(), 3 ) != String::View::npos; + + if ( !isSingleLineBlock ) { + // Start a new code block + inCodeBlock = true; + codeBlockStart = static_cast( lineIdx ); + } } else if ( String::startsWith( trimmed, "#" ) ) { // Check if it's a valid heading size_t hashCount = 0;