From ee1ba7e6505df77a55554eaa0fab82f357da81b8 Mon Sep 17 00:00:00 2001 From: zufuliu Date: Sun, 19 Jan 2025 14:08:58 +0800 Subject: [PATCH] Minor update VB code folding. --- scintilla/lexers/LexVB.cxx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scintilla/lexers/LexVB.cxx b/scintilla/lexers/LexVB.cxx index c0195c6c90..4bdf2ef39c 100644 --- a/scintilla/lexers/LexVB.cxx +++ b/scintilla/lexers/LexVB.cxx @@ -477,6 +477,11 @@ struct FoldLineState { } }; +inline bool IsCodeFolding(const char *s, unsigned wordLen) noexcept { + const char *p = strstr(" interface module namespace operator synclock try using ", s); + return p != nullptr && p[-1] == ' ' && p[wordLen] == ' '; +} + void FoldVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, LexerWordList /*keywordLists*/, Accessor &styler) { const Language language = static_cast(styler.GetPropertyInt("lexer.lang")); const Sci_PositionU endPos = startPos + lengthDoc; @@ -511,7 +516,6 @@ void FoldVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, Le } if (style != initStyle) { s[wordLen] = '\0'; - wordLen = 0; if (style == SCE_VB_KEYWORD) { const KeywordType kwPrev = kwType; kwType = KeywordType::None; @@ -586,7 +590,7 @@ void FoldVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, Le kwType = KeywordType::SkipWhile; } else if (StrEqual(s, "custom")) { kwType = KeywordType::CustomEvent; - } else if (StrEqualsAny(s, "try", "using", "module", "operator", "synclock", "interface", "namespace") + } else if (IsCodeFolding(s, wordLen) || (kwPrev == KeywordType::CustomEvent && StrEqual(s, "event")) || (chNext == '(' && StrEqualsAny(s, "addhandler", "removehandler", "raiseevent")) || (!foldCurrent.IsInterfaceBlock() && StrEqual(s, "structure"))) { @@ -607,6 +611,7 @@ void FoldVBDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, Le levelNext++; } } + wordLen = 0; } } else if (style == SCE_VB_OPERATOR) { kwType = KeywordType::None;