diff --git a/scintilla/lexers/LexAPDL.cxx b/scintilla/lexers/LexAPDL.cxx index efbe29d271..52d3c20d66 100644 --- a/scintilla/lexers/LexAPDL.cxx +++ b/scintilla/lexers/LexAPDL.cxx @@ -234,6 +234,7 @@ void FoldAPDLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int /*initStyle if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.dataLine) { diff --git a/scintilla/lexers/LexAsm.cxx b/scintilla/lexers/LexAsm.cxx index 4a0d3129d0..b4714e1301 100644 --- a/scintilla/lexers/LexAsm.cxx +++ b/scintilla/lexers/LexAsm.cxx @@ -450,6 +450,7 @@ void FoldAsmDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lexe } } if (atEOL || (i == endPos - 1)) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) diff --git a/scintilla/lexers/LexAsymptote.cxx b/scintilla/lexers/LexAsymptote.cxx index 08b1bcb4a2..7693959011 100644 --- a/scintilla/lexers/LexAsymptote.cxx +++ b/scintilla/lexers/LexAsymptote.cxx @@ -297,6 +297,7 @@ void FoldAsyDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, L } if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.moduleImport) { diff --git a/scintilla/lexers/LexAutoHotkey.cxx b/scintilla/lexers/LexAutoHotkey.cxx index 3ee09870e2..bff39e0702 100644 --- a/scintilla/lexers/LexAutoHotkey.cxx +++ b/scintilla/lexers/LexAutoHotkey.cxx @@ -834,6 +834,7 @@ void FoldAHKDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, L } if (startPos == lineStartNext) { const int lineCommentNext = GetLineCommentState(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineCommentCurrent) { levelNext += lineCommentNext - lineCommentPrev; } else if (visibleChars) { diff --git a/scintilla/lexers/LexAutoIt3.cxx b/scintilla/lexers/LexAutoIt3.cxx index b75fe446ca..ba2fad5757 100644 --- a/scintilla/lexers/LexAutoIt3.cxx +++ b/scintilla/lexers/LexAutoIt3.cxx @@ -721,6 +721,7 @@ void FoldAU3Doc(Sci_PositionU startPos, Sci_Position length, int, LexerWordList, levelCurrent--; } } + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) { diff --git a/scintilla/lexers/LexAviSynth.cxx b/scintilla/lexers/LexAviSynth.cxx index 045408ef34..d11850fb53 100644 --- a/scintilla/lexers/LexAviSynth.cxx +++ b/scintilla/lexers/LexAviSynth.cxx @@ -314,6 +314,7 @@ void FoldAvsDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, L } if (startPos == lineStartNext) { const int lineCommentNext = GetLineCommentState(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineCommentCurrent) { levelNext += lineCommentNext - lineCommentPrev; } else if (visibleChars) { diff --git a/scintilla/lexers/LexAwk.cxx b/scintilla/lexers/LexAwk.cxx index f433fcd34b..cebc939e39 100644 --- a/scintilla/lexers/LexAwk.cxx +++ b/scintilla/lexers/LexAwk.cxx @@ -444,6 +444,7 @@ void FoldAwkDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int /*initStyle* } if (++startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.fileInclude) { diff --git a/scintilla/lexers/LexBash.cxx b/scintilla/lexers/LexBash.cxx index 80578e5464..5953a29a4f 100644 --- a/scintilla/lexers/LexBash.cxx +++ b/scintilla/lexers/LexBash.cxx @@ -955,6 +955,7 @@ void FoldBashDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lex } if (startPos == lineStartNext) { + levelCurrent = sci::max(levelCurrent, SC_FOLDLEVELBASE); // Comment folding if (IsCommentLine(lineCurrent)) { levelCurrent += IsCommentLine(lineCurrent + 1) - IsCommentLine(lineCurrent - 1); diff --git a/scintilla/lexers/LexBatch.cxx b/scintilla/lexers/LexBatch.cxx index db079cf8ac..758b00b036 100644 --- a/scintilla/lexers/LexBatch.cxx +++ b/scintilla/lexers/LexBatch.cxx @@ -643,6 +643,7 @@ void ColouriseBatchDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initS } } + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) { diff --git a/scintilla/lexers/LexCIL.cxx b/scintilla/lexers/LexCIL.cxx index 6894ba5eff..ef30d3ce38 100644 --- a/scintilla/lexers/LexCIL.cxx +++ b/scintilla/lexers/LexCIL.cxx @@ -206,6 +206,7 @@ void FoldCILDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lexe } if (atEOL || (i == endPos - 1)) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) diff --git a/scintilla/lexers/LexCMake.cxx b/scintilla/lexers/LexCMake.cxx index 138f7a7c1f..47af28eea1 100644 --- a/scintilla/lexers/LexCMake.cxx +++ b/scintilla/lexers/LexCMake.cxx @@ -397,6 +397,7 @@ void FoldCMakeDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, if (++startPos == lineStartNext) { const int lineCommentNext = GetLineCommentState(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineCommentCurrent) { levelNext += lineCommentNext - lineCommentPrev; } diff --git a/scintilla/lexers/LexCPP.cxx b/scintilla/lexers/LexCPP.cxx index ac45e5ce3d..f6249a810b 100644 --- a/scintilla/lexers/LexCPP.cxx +++ b/scintilla/lexers/LexCPP.cxx @@ -965,6 +965,7 @@ void FoldCppDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lexe if (visibleChars == 0 && !isspacechar(ch)) visibleChars++; if (atEOL || (i == endPos - 1)) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) diff --git a/scintilla/lexers/LexCSS.cxx b/scintilla/lexers/LexCSS.cxx index a699272df8..87b7e9addd 100644 --- a/scintilla/lexers/LexCSS.cxx +++ b/scintilla/lexers/LexCSS.cxx @@ -361,6 +361,7 @@ void ColouriseCssDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSty } if (sc.atLineEnd) { if (fold) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) { diff --git a/scintilla/lexers/LexCSharp.cxx b/scintilla/lexers/LexCSharp.cxx index 38e9263729..3d4335cd82 100644 --- a/scintilla/lexers/LexCSharp.cxx +++ b/scintilla/lexers/LexCSharp.cxx @@ -883,6 +883,7 @@ void FoldCSharpDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle } if (++startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.usingName) { diff --git a/scintilla/lexers/LexConfig.cxx b/scintilla/lexers/LexConfig.cxx index 9e4acce50c..9b03718366 100644 --- a/scintilla/lexers/LexConfig.cxx +++ b/scintilla/lexers/LexConfig.cxx @@ -263,6 +263,7 @@ void FoldConfDoc(Sci_PositionU startPos, Sci_Position length, int /*initStyle*/, visibleChars++; } if (atEOL || (i == endPos - 1)) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) diff --git a/scintilla/lexers/LexD.cxx b/scintilla/lexers/LexD.cxx index 71a561e41c..fb3389d1df 100644 --- a/scintilla/lexers/LexD.cxx +++ b/scintilla/lexers/LexD.cxx @@ -739,6 +739,7 @@ void FoldDDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, Lex } if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.packageImport) { diff --git a/scintilla/lexers/LexDart.cxx b/scintilla/lexers/LexDart.cxx index 6d573cadf8..a0bf77100f 100644 --- a/scintilla/lexers/LexDart.cxx +++ b/scintilla/lexers/LexDart.cxx @@ -537,6 +537,7 @@ void FoldDartDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, } if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.packageImport) { diff --git a/scintilla/lexers/LexFortran.cxx b/scintilla/lexers/LexFortran.cxx index 6e691eaf95..a7d18c8292 100644 --- a/scintilla/lexers/LexFortran.cxx +++ b/scintilla/lexers/LexFortran.cxx @@ -381,6 +381,7 @@ void FoldFortranDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int /*initSt if (++startPos == lineStartNext) { const int lineCommentNext = GetLineCommentState(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineCommentCurrent) { levelNext += lineCommentNext - lineCommentPrev; } diff --git a/scintilla/lexers/LexGo.cxx b/scintilla/lexers/LexGo.cxx index db5a7543fb..7f6f777d65 100644 --- a/scintilla/lexers/LexGo.cxx +++ b/scintilla/lexers/LexGo.cxx @@ -616,6 +616,7 @@ void FoldGoDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, Le } if (startPos == lineStartNext) { const int lineCommentNext = GetLineCommentState(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineCommentCurrent) { levelNext += lineCommentNext - lineCommentPrev; } else if (visibleChars) { diff --git a/scintilla/lexers/LexGraphViz.cxx b/scintilla/lexers/LexGraphViz.cxx index 6697979c1f..54ff3df4c7 100644 --- a/scintilla/lexers/LexGraphViz.cxx +++ b/scintilla/lexers/LexGraphViz.cxx @@ -239,6 +239,7 @@ void ColouriseGraphVizDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int in styler.SetLineState(sc.currentLine, (htmlTagLevel << 4) | htmlCommentStyle); visibleChars = 0; if (fold) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) { diff --git a/scintilla/lexers/LexGroovy.cxx b/scintilla/lexers/LexGroovy.cxx index 7108cc4aaf..80840eb860 100644 --- a/scintilla/lexers/LexGroovy.cxx +++ b/scintilla/lexers/LexGroovy.cxx @@ -651,6 +651,7 @@ void FoldGroovyDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle } if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.packageImport) { diff --git a/scintilla/lexers/LexHTML.cxx b/scintilla/lexers/LexHTML.cxx index 49e5930d49..40645b43fd 100644 --- a/scintilla/lexers/LexHTML.cxx +++ b/scintilla/lexers/LexHTML.cxx @@ -511,6 +511,7 @@ void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, int init // Avoid triggering two times on Dos/Win // New line -> record any line state onto /next/ line if (fold) { + levelCurrent = sci::max(levelCurrent, SC_FOLDLEVELBASE); int lev = levelPrev; if ((levelCurrent > levelPrev)) lev |= SC_FOLDLEVELHEADERFLAG; diff --git a/scintilla/lexers/LexHaxe.cxx b/scintilla/lexers/LexHaxe.cxx index 704aa57677..ee29c563b0 100644 --- a/scintilla/lexers/LexHaxe.cxx +++ b/scintilla/lexers/LexHaxe.cxx @@ -474,6 +474,7 @@ void FoldHaxeDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, } if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.packageImport) { diff --git a/scintilla/lexers/LexInno.cxx b/scintilla/lexers/LexInno.cxx index 181bad1c06..635f7a3c20 100644 --- a/scintilla/lexers/LexInno.cxx +++ b/scintilla/lexers/LexInno.cxx @@ -505,6 +505,7 @@ void FoldInnoDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, if (startPos == lineStartNext) { const int lineStateNext = styler.GetLineState(lineCurrent + 1); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineState & InnoLineStateSectionHeader) { levelCurrent = SC_FOLDLEVELBASE; levelNext = SC_FOLDLEVELBASE + 1; diff --git a/scintilla/lexers/LexJSON.cxx b/scintilla/lexers/LexJSON.cxx index d603a8907a..6cea373479 100644 --- a/scintilla/lexers/LexJSON.cxx +++ b/scintilla/lexers/LexJSON.cxx @@ -256,6 +256,7 @@ void ColouriseJSONDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt atLineStart = startPos == lineStartNext; if (atLineStart) { if (fold) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) { diff --git a/scintilla/lexers/LexJam.cxx b/scintilla/lexers/LexJam.cxx index f4778e5d3c..cdcc669085 100644 --- a/scintilla/lexers/LexJam.cxx +++ b/scintilla/lexers/LexJam.cxx @@ -291,6 +291,7 @@ void FoldJamDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, L } if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.moduleImport) { diff --git a/scintilla/lexers/LexJava.cxx b/scintilla/lexers/LexJava.cxx index 522555f588..d32f2c9c18 100644 --- a/scintilla/lexers/LexJava.cxx +++ b/scintilla/lexers/LexJava.cxx @@ -658,6 +658,7 @@ void FoldJavaDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, } if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.packageImport) { diff --git a/scintilla/lexers/LexJavaScript.cxx b/scintilla/lexers/LexJavaScript.cxx index 8298c2743b..0601ab0d32 100644 --- a/scintilla/lexers/LexJavaScript.cxx +++ b/scintilla/lexers/LexJavaScript.cxx @@ -676,6 +676,7 @@ void FoldJsDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, Le } if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.packageImport) { diff --git a/scintilla/lexers/LexJulia.cxx b/scintilla/lexers/LexJulia.cxx index 334a54b872..accaaa7853 100644 --- a/scintilla/lexers/LexJulia.cxx +++ b/scintilla/lexers/LexJulia.cxx @@ -647,6 +647,7 @@ void FoldJuliaDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, if (startPos == lineStartNext) { const int lineCommentNext = GetLineCommentState(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineCommentCurrent) { levelNext += lineCommentNext - lineCommentPrev; } diff --git a/scintilla/lexers/LexKotlin.cxx b/scintilla/lexers/LexKotlin.cxx index b7a48c594e..84ca8e1776 100644 --- a/scintilla/lexers/LexKotlin.cxx +++ b/scintilla/lexers/LexKotlin.cxx @@ -461,6 +461,7 @@ void FoldKotlinDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle } if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.packageImport) { diff --git a/scintilla/lexers/LexLaTeX.cxx b/scintilla/lexers/LexLaTeX.cxx index a3d631bd61..7a727d1bcf 100644 --- a/scintilla/lexers/LexLaTeX.cxx +++ b/scintilla/lexers/LexLaTeX.cxx @@ -352,6 +352,7 @@ void FoldLatexDoc(Sci_PositionU startPos, Sci_Position length, int /*initStyle*/ } if (atEOL || (i == endPos - 1)) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) diff --git a/scintilla/lexers/LexLisp.cxx b/scintilla/lexers/LexLisp.cxx index 8888a24afa..1619890c11 100644 --- a/scintilla/lexers/LexLisp.cxx +++ b/scintilla/lexers/LexLisp.cxx @@ -198,6 +198,7 @@ void FoldListDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lex } if (atEOL || (i == endPos - 1)) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) diff --git a/scintilla/lexers/LexLua.cxx b/scintilla/lexers/LexLua.cxx index 2498c9fdd4..4da101caa8 100644 --- a/scintilla/lexers/LexLua.cxx +++ b/scintilla/lexers/LexLua.cxx @@ -433,6 +433,7 @@ void FoldLuaDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, L if (startPos == lineStartNext) { const int lineCommentNext = GetLineCommentState(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineCommentCurrent) { levelNext += lineCommentNext - lineCommentPrev; } diff --git a/scintilla/lexers/LexMakefile.cxx b/scintilla/lexers/LexMakefile.cxx index 97a528f292..ea8190b694 100644 --- a/scintilla/lexers/LexMakefile.cxx +++ b/scintilla/lexers/LexMakefile.cxx @@ -285,6 +285,7 @@ void FoldMakeDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lex visibleChars++; if (atEOL || (i == endPos - 1)) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) diff --git a/scintilla/lexers/LexMathematica.cxx b/scintilla/lexers/LexMathematica.cxx index 0d6d741583..2f826473ea 100644 --- a/scintilla/lexers/LexMathematica.cxx +++ b/scintilla/lexers/LexMathematica.cxx @@ -153,6 +153,7 @@ void ColouriseMathematicaDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int } if (sc.atLineEnd) { if (fold) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) { diff --git a/scintilla/lexers/LexMatlab.cxx b/scintilla/lexers/LexMatlab.cxx index e334642049..323dcef22f 100644 --- a/scintilla/lexers/LexMatlab.cxx +++ b/scintilla/lexers/LexMatlab.cxx @@ -382,6 +382,7 @@ void FoldMatlabDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, L visibleChars++; if (atEOL || (i == endPos - 1)) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) diff --git a/scintilla/lexers/LexNSIS.cxx b/scintilla/lexers/LexNSIS.cxx index 6ad4ea9e19..c4338fb680 100644 --- a/scintilla/lexers/LexNSIS.cxx +++ b/scintilla/lexers/LexNSIS.cxx @@ -267,6 +267,7 @@ void FoldNSISDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, if (startPos == lineStartNext) { const int lineTypeNext = styler.GetLineState(lineCurrent + 1) & NsisLineTypeMask; + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineTypeCurrent) { levelNext += (lineTypeNext == lineTypeCurrent) - (lineTypePrev == lineTypeCurrent); } diff --git a/scintilla/lexers/LexPHP.cxx b/scintilla/lexers/LexPHP.cxx index 0e14ab5fe5..35bbaf420e 100644 --- a/scintilla/lexers/LexPHP.cxx +++ b/scintilla/lexers/LexPHP.cxx @@ -1550,6 +1550,7 @@ void FoldPHPDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, L } if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.useNamespace) { diff --git a/scintilla/lexers/LexPascal.cxx b/scintilla/lexers/LexPascal.cxx index 728963a520..4b3a0dd653 100644 --- a/scintilla/lexers/LexPascal.cxx +++ b/scintilla/lexers/LexPascal.cxx @@ -420,6 +420,7 @@ void FoldPascalDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, L if (atEOL || (i == endPos - 1)) { int lev = levelPrev; + levelCurrent = sci::max(levelCurrent, SC_FOLDLEVELBASE); if ((levelCurrent > levelPrev)) lev |= SC_FOLDLEVELHEADERFLAG; styler.SetLevel(lineCurrent, lev); diff --git a/scintilla/lexers/LexPerl.cxx b/scintilla/lexers/LexPerl.cxx index 4382d9824c..c64a2ad725 100644 --- a/scintilla/lexers/LexPerl.cxx +++ b/scintilla/lexers/LexPerl.cxx @@ -1655,6 +1655,7 @@ void FoldPerlDoc(Sci_PositionU startPos, Sci_Position length, int /*initStyle*/, atLineStart = startPos == lineStartNext; if (atLineStart) { // Comment folding + levelCurrent = sci::max(levelCurrent, SC_FOLDLEVELBASE); if (IsCommentLine(lineCurrent)) { levelCurrent += IsCommentLine(lineCurrent + 1) - IsCommentLine(lineCurrent - 1); } diff --git a/scintilla/lexers/LexPowerShell.cxx b/scintilla/lexers/LexPowerShell.cxx index 229cc2bdd0..cc06e0f48a 100644 --- a/scintilla/lexers/LexPowerShell.cxx +++ b/scintilla/lexers/LexPowerShell.cxx @@ -470,6 +470,7 @@ void FoldPowerShellDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initS } if (startPos == lineStartNext) { const int lineCommentNext = GetLineCommentState(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineCommentCurrent) { levelNext += lineCommentNext - lineCommentPrev; } else if (visibleChars) { diff --git a/scintilla/lexers/LexR.cxx b/scintilla/lexers/LexR.cxx index 4b53b2f327..2e32f5a1e3 100644 --- a/scintilla/lexers/LexR.cxx +++ b/scintilla/lexers/LexR.cxx @@ -377,6 +377,7 @@ void FoldSimpleDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int /*initSty if (++startPos == lineStartNext) { const int lineCommentNext = GetLineCommentState(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineCommentCurrent) { levelNext += lineCommentNext - lineCommentPrev; } diff --git a/scintilla/lexers/LexRebol.cxx b/scintilla/lexers/LexRebol.cxx index 65acca3f1c..2ad70e9330 100644 --- a/scintilla/lexers/LexRebol.cxx +++ b/scintilla/lexers/LexRebol.cxx @@ -445,6 +445,7 @@ void FoldRebolDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int /*initStyl if (++startPos == lineStartNext) { const int lineTypeNext = styler.GetLineState(lineCurrent + 1) & RebolLineTypeMask; + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineTypeCurrent) { levelNext += (lineTypeNext == lineTypeCurrent) - (lineTypePrev == lineTypeCurrent); } diff --git a/scintilla/lexers/LexRuby.cxx b/scintilla/lexers/LexRuby.cxx index 4d032c38fd..4005713364 100644 --- a/scintilla/lexers/LexRuby.cxx +++ b/scintilla/lexers/LexRuby.cxx @@ -1741,7 +1741,7 @@ void FoldRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lexer synchronizeDocStart(startPos, length, initStyle, styler, false); const Sci_PositionU endPos = startPos + length; Sci_Line lineCurrent = styler.GetLine(startPos); - int levelPrev = startPos == 0 ? 0 : (styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK & ~SC_FOLDLEVELBASE); + int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK; int levelCurrent = levelPrev; uint8_t chPrev = '\0'; uint8_t chNext = styler[startPos]; @@ -1779,10 +1779,7 @@ void FoldRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lexer if (ch == '(' || ch == '{' || ch == '[') { levelCurrent++; } else if (ch == ')' || ch == '}' || ch == ']') { - // Don't decrement below 0 - if (levelCurrent > 0) { - levelCurrent--; - } + levelCurrent--; } } else if (style == SCE_RB_WORD && styleNext != SCE_RB_WORD) { // Look at the keyword on the left and decide what to do @@ -1790,9 +1787,7 @@ void FoldRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lexer prevWord[0] = 0; getPrevWord(startPos - 1, prevWord, styler, SCE_RB_WORD); if (StrEqual(prevWord, "end")) { - // Don't decrement below 0 - if (levelCurrent > 0) - levelCurrent--; + levelCurrent--; } else if (StrEqual(prevWord, "def")) { levelCurrent++; method_definition = MethodDefinition::Define; @@ -1868,6 +1863,7 @@ void FoldRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lexer chPrev = ch; stylePrev = style; if (startPos == lineStartNext) { + levelCurrent = sci::max(levelCurrent, SC_FOLDLEVELBASE); if (IsCommentLine(lineCurrent)) { levelCurrent += IsCommentLine(lineCurrent + 1) - IsCommentLine(lineCurrent - 1); } @@ -1875,7 +1871,7 @@ void FoldRbDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lexer int lev = levelPrev; if ((levelCurrent > levelPrev)) lev |= SC_FOLDLEVELHEADERFLAG; - styler.SetLevel(lineCurrent, lev | SC_FOLDLEVELBASE); + styler.SetLevel(lineCurrent, lev); lineCurrent++; lineStartNext = styler.LineStart(lineCurrent + 1); lineStartNext = sci::min(lineStartNext, endPos); diff --git a/scintilla/lexers/LexRust.cxx b/scintilla/lexers/LexRust.cxx index da8cf9ece1..e1c95eb4c2 100644 --- a/scintilla/lexers/LexRust.cxx +++ b/scintilla/lexers/LexRust.cxx @@ -601,6 +601,7 @@ void FoldRustDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, } if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.pubUse) { diff --git a/scintilla/lexers/LexSQL.cxx b/scintilla/lexers/LexSQL.cxx index 865640d823..5812608d19 100644 --- a/scintilla/lexers/LexSQL.cxx +++ b/scintilla/lexers/LexSQL.cxx @@ -761,6 +761,7 @@ void FoldSqlDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lexe } } if (atEOL || (i == endPos - 1)) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) diff --git a/scintilla/lexers/LexSmali.cxx b/scintilla/lexers/LexSmali.cxx index 939b879cf2..7c0dd4d371 100644 --- a/scintilla/lexers/LexSmali.cxx +++ b/scintilla/lexers/LexSmali.cxx @@ -366,6 +366,7 @@ void FoldSmaliDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Le } if (atEOL || (i == endPos - 1)) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) diff --git a/scintilla/lexers/LexSwift.cxx b/scintilla/lexers/LexSwift.cxx index 33ada4fe60..295862ce72 100644 --- a/scintilla/lexers/LexSwift.cxx +++ b/scintilla/lexers/LexSwift.cxx @@ -574,6 +574,7 @@ void FoldSwiftDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, } if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.packageImport) { diff --git a/scintilla/lexers/LexTCL.cxx b/scintilla/lexers/LexTCL.cxx index aa02036223..5964a2315b 100644 --- a/scintilla/lexers/LexTCL.cxx +++ b/scintilla/lexers/LexTCL.cxx @@ -333,7 +333,9 @@ void ColouriseTCLDoc(Sci_PositionU startPos, Sci_Position length, int, LexerWord case '}': sc.SetState(SCE_TCL_OPERATOR); expected = true; - --currentLevel; + if (currentLevel > 0) { + --currentLevel; + } break; case '[': expected = true; diff --git a/scintilla/lexers/LexTexinfo.cxx b/scintilla/lexers/LexTexinfo.cxx index ba4af46bcc..c598f8468e 100644 --- a/scintilla/lexers/LexTexinfo.cxx +++ b/scintilla/lexers/LexTexinfo.cxx @@ -334,6 +334,7 @@ void ColouriseTexiDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSt levelCurrent = levelNext - 1; headerLevel = 0; } + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) { diff --git a/scintilla/lexers/LexVB.cxx b/scintilla/lexers/LexVB.cxx index e10c6630f8..4eb0334457 100644 --- a/scintilla/lexers/LexVB.cxx +++ b/scintilla/lexers/LexVB.cxx @@ -493,6 +493,7 @@ void FoldVBDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, Lexer visibleChars++; if (atEOL || (i == endPos - 1)) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) diff --git a/scintilla/lexers/LexVHDL.cxx b/scintilla/lexers/LexVHDL.cxx index ba91f9c14f..3818fb24ad 100644 --- a/scintilla/lexers/LexVHDL.cxx +++ b/scintilla/lexers/LexVHDL.cxx @@ -444,6 +444,7 @@ void FoldVHDLDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, if (startPos == lineStartNext) { const int lineCommentNext = GetLineCommentState(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineCommentCurrent) { levelNext += lineCommentNext - lineCommentPrev; } diff --git a/scintilla/lexers/LexVerilog.cxx b/scintilla/lexers/LexVerilog.cxx index b8e0ab6f45..c0dd107a74 100644 --- a/scintilla/lexers/LexVerilog.cxx +++ b/scintilla/lexers/LexVerilog.cxx @@ -571,6 +571,7 @@ void FoldVerilogDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyl if (startPos == lineStartNext) { const int lineCommentNext = GetLineCommentState(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineCommentCurrent) { levelNext += lineCommentNext - lineCommentPrev; } diff --git a/scintilla/lexers/LexVim.cxx b/scintilla/lexers/LexVim.cxx index 59d538587c..251cecb567 100644 --- a/scintilla/lexers/LexVim.cxx +++ b/scintilla/lexers/LexVim.cxx @@ -334,6 +334,7 @@ void FoldVimDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int /*initStyle* if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } diff --git a/scintilla/lexers/LexWASM.cxx b/scintilla/lexers/LexWASM.cxx index e196c7033b..3ae5b2e7f4 100644 --- a/scintilla/lexers/LexWASM.cxx +++ b/scintilla/lexers/LexWASM.cxx @@ -253,6 +253,7 @@ void FoldWASMDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int /*initStyle if (startPos == lineStartNext) { const int lineCommentNext = GetLineCommentState(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (lineCommentCurrent) { levelNext += lineCommentNext - lineCommentPrev; } diff --git a/scintilla/lexers/LexWinHex.cxx b/scintilla/lexers/LexWinHex.cxx index 04d91d000f..de525720b3 100644 --- a/scintilla/lexers/LexWinHex.cxx +++ b/scintilla/lexers/LexWinHex.cxx @@ -116,6 +116,7 @@ void ColouriseWinHexDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int init if (sc.atLineEnd) { visibleChars = 0; if (fold) { + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); const int levelUse = levelCurrent; int lev = levelUse | levelNext << 16; if (levelUse < levelNext) { diff --git a/scintilla/lexers/LexZig.cxx b/scintilla/lexers/LexZig.cxx index 299f08ed75..128247dc95 100644 --- a/scintilla/lexers/LexZig.cxx +++ b/scintilla/lexers/LexZig.cxx @@ -373,6 +373,7 @@ void FoldZigDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, L ++startPos; if (startPos == lineStartNext) { const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = sci::max(levelNext, SC_FOLDLEVELBASE); if (foldCurrent.lineComment) { levelNext += foldNext.lineComment - foldPrev.lineComment; } else if (foldCurrent.multilineString) {