Ok took me a while. It actually is a hack / hardcoded.
procedure TSynCustomHighlighter.ScanRanges;
..
CurrentLines.SendHighlightChanged(StartIndex - 1, EndIndex - StartIndex + 1)
That is PasHl does not rescan the line above. IIRC It stores info (for Fold...Lever) on the next line, and if the HL is ask for info on a line, it checks the info stored on the next line.
"rescan" here means: in ScanRanges.
Each line is also scanned for other reasons, such as painting, or the fold-provider asking to scan a line (which IIRC is only done if Fold...Level, indicate a need for that)
But the HL tells SynEdit to invalidate/paint one line above the scan begin => and thus the fold provider re-evals that line....
(that is the code above, sending the invalidated range)
But you can subclass CurrentRanges, and when it sets the first line needed to be scanned => to what you need.
That does mean a lot more scanning....
Better, find a way to store info, so that the main-scan does not need to redo the lines above.
Override PerformScan.The you can do several things:
- At the end of PerformScan => Send your own invalidate range. (so lines above will be repainted if needed).
Sending the message twice is harmless, so don't worry that part of it will be sent again.
- You can either go back at the start of PerformScan, and find your ideal startline. But better not.
- Or: While you scan a line, check if the fold info on the previous lines "range" is correct. And only if not, then iterate back over those ranges and update them (you probably do not need to scan those lines for this, just access the ranges)
When you go back, keep the info, as this is what you need to invalidate for painting.....
Note, if you update a range, you must copy it, and update the copy.
Then stare it with "fRanges.GetEqual(FCodeFoldRange);"
See GetRange and SetRange.
One and the same range object is used for many lines. So if you update it without those steps, you change a lot more than you wanted....
"getrange" actually has some (old) documentation) (in the xml docs / fpdoc)
Hope that helps