SynEdit - Add support code folding for Java lazarus / 13-General ---------------------------------------------------------------------- bubulemaster · 2009-08-29 08:48 Hi, I try add code folding support for SynHighlighterJava unit for submit after to Lazarus project. I have a very big problem. When your enter brace ({ or }), it's calling many times but TSynJavaSynRange(CodeFoldRange).CodeFoldStackSize are not reinit beetwen call. Thus, for same open brace it add 3 or more open node. If you test SynHighlighterPas, we have not problem. Somebody know what is the problem ? I've attach my file. All my modifications are surrounded by Add emeric / End add emeric Another stange behavior, if I had code foldind support in comment (/* */), I've not the problème but, close node is always on the line after. Example : /* -> open node [empty] -> close node */ -> nothing Thank you for your help I use Lazarus 0.9.26-2 ---------------------------------------------------------------------- Martin_fr · 2009-08-29 11:36 I would recommend to use the latest SVN, otherwise it is more than likely your code will stop working when you upgrade. In SVN there is a special base class for fold-highlighter: TSynCustomFoldHighlighter You want to look at the procedure SetLine in TSynCustomFoldHighlighter and TSynPasSyn (the pascal highlighter). Maybe also SetRange / ResetRange. But ignore all LevelIfDef* / LevelRegion* => the pascal highlighter keeps 3 different set of counters (all using the same logic). This is because ifdef/region can overlap each other. Important is that you re-initialize all the fold levels for the line. A line may get scanned more than once, if you do not reset the level, then your results will increase (as you have it). There are 2 important counters: * FoldEndLevel: Level at the end of line (equals start of next line) * FoldMinLevel: Minimum level on this line. This can be lower than the start/end level. See example:   begin       // endlevel = 1 ; minlevel = 0   end  begin // endlevel = 1 ; minlevel = 0   end         // endlevel = 0 ; minlevel = 0 LastLineFix will not be needed. it is used where a keyword closes a block. but the close ought to be in the last line (fold-able car/type sections)   type       a=integer;  // the fold ends with this line   var               // but it is only known, when parsing the "var"      b:a; Let me know if you have any specific questions. ---------------------------------------------------------------------- bubulemaster · 2009-08-30 10:15 Ok, I'm tryng last SVN version but, first I finished my SynEdit documentation Thank you