ScintillaOrg / lexilla

A library of language lexers for use with Scintilla
https://www.scintilla.org/Lexilla.html
Other
163 stars 59 forks source link

Incorrect folding for multi-line literal strings and block comments when performed incrementally #247

Open nyamatongwe opened 1 month ago

nyamatongwe commented 1 month ago

For a multi-line literal string SCE_LUA_LITERALSTRING or block comment SCE_LUA_COMMENT, lexing the whole element produces correct folding but scrolling through the element produces negative folding levels.

The folding code checks for transitions out of the literal or comment state and treats these as ending the element so decrements the fold level which was incremented for the element start. The detection relies on reading the next styling byte but, for the final text byte, this is not yet set and is likely 0.

To fix this, the beyond-end style byte is assumed to be the same as the previous byte. Both of these elements end with ]] followed by a different style except for end-of-file so this is safe. The case where the ]] appears at file end is also OK because fold handling treats this as end of folding element as well.

nyamatongwe commented 1 month ago

Example with visible fold levels.

xpm1 = [[/* XPM */
static char * arrow_xpm[] = {
"12 12 3 1",
"   c None",
".  c #000000",
"+  c #808080",
"            ",
"     .+     ",
"      .+    ",
"      +.+   ",
" ........+  ",
" .........+ ",
" .........+ ",
" ........+  ",
"      +.+   ",
"      .+    ",
"     .+     ",
"            "};
]]

LuaBadFold