I think nothing in the unit FoldedView will be of help (except maybe by serving as example)
But lets look at the classes you picked out:
Unfortunately, TCustomSynEdit instantiates its TextView by directly calling the constructor on TSynEditFoldedView
That may get fixed, but first the inheritance of TSynEditFoldedView must be fixed (it needs to be a TSynEditStringsLinked).
And there needs to be a manager for all TSynEditStringsLinked. And that would be where hooks can go in.
I've looked also at TSynEditFoldProvider and this class does not have any public or protected virtual methods that could be used to react to changes in the TSynTextFoldAVLTree. Incidentally, TSynTextFoldAVLTree does not have any events either when it inserts, delete or modify a node.
TSynTextFoldAVLTree.
This ONLY store currently folded nodes. (if you collapse a fold in the editor, it will be added to that list)
TSynEditFoldProvider
Allows to find where (on which line) text can be folded.
It mostly forwards info from the highlighter.
But it also adds the current selection (as you can hide selected text)
TLasSynDisplayView (in general, not specific to the one in FoldedView )
Well this could be used to modify highlights. But it really by design is not the place. (not for your case)
It *maps" the text in memory, to the display-able text.
For example it adds the [...] (the marker far a collapsed block) into the text, so this is painted with the normal text.
It can modify highlights, but really be careful with that.
There are 2 places, and only 2, that you should consider for highlight.
1) the highlighter (and yes it can mix colors (see pascal "case" labels)
2) the markup classes (SynEditMarkup...)
Both will work for you.
The difficulty here is that I'm duplicating a structure that already exists (TSynTextFoldAVLTree) instead of using it.
Actually you would be using it for other data.
Yes you can use this class to keep track of your locations.
The existing instance, is empty if nothing is currently collapsed. So it does not contain the data you need.
-----------------------------------
1) choice you need to make
how to maintain the location of define/undef/ifdef
a) you can do in your own code
b) you can do in your highlighter.
But for b, you must add extra foldblocktypes. (I did hint on that before)
If you do use foldblocks for anything, and you need to find them:
TLazSynEditNestedFoldsList
You can give it a line, and it gets you info for that line, and finds previous lines with foldblocks still open at the current.
The only way to find all lines with a certain foldblock-type, is to scan through all line.
If you need an index, you need to keep it yourself.
(In the IDE codetools keeps track of define/ifdef // though the HL has ifdefs, like any other fold, but only accesible if you know the line already)
2)
if you tread all of them as fold blocks, you can do the highlighing in the highlighter too.
If you keep info outside the HL, then you will need a Markup for it.
-----------------------
folding of a define/ifdef
- say you have 19 blocktyes already (begin/while/try/procedure/....)
you have a stringlist with the names of defines
when parsing a "DEFINE foo"
n := stringlist.indexOf(foo) // case sense ??? // add if not yet in list
n := 20 + n *4 ; // 3 is enough but 4 maybe easier / we use 20 because it divides by 4
StartCodeFoldBlock(n)
same for UNDEF, close the folds
for IFDEF foo, ENDIF again the same, but
n := 20 + n *2 + 1; // use +1, so they do not conflict
OR
n := 20 + n *2 + 2; // use +2, if this should lowlgiht
when you encounter an IFDEF, during scanning (in procedure Next)
so you do have the current range, and you can walk up the tree of foldblocks.
n2 := n and $fffffffC // last 2 bits // value dividable by 4
now when you open
search the tree of foldblocks, for n2, if it is in the tree, "foo" is defined.
if foo is defined use "+2" otherwise "+1"
if you use +2 set a flag on the range. Use the flag when you decide if you lowlgiht the token.
on endif, clear the flag (but check outer nodes, if they have +2 then keep the flag)