PositionHighlighter is very old, and could probably be improved.
A token is a part of the line9in pascal it may be a symbol, keyword, text, number,...). But a token is not necessary bound to the flow of the text. It could spawn across many words, or end in the middle of the text.
The end of one token must always be the start of the next. No part of the line must be left out, no overlaps, and the order must be the same as in the line.
PositionHighlighter returns all text, that is not in user specified tokens, as tkText-tokens.
Now ideally, the user could define a token as from x1 to x2, but the PHl needs to check every new token added, and reject any token that overlaps (it can still fill the gaps with tktext)
So now you just specify the end pos of a token, and it starts from the end of the previous token (or start of line)
I did not invent that, nor do I say it's good. I just describe what I observed....
Anyway, if the highlighter is called as in synedit.pp line 3750
fHighlighter.StartAtLineIndex(CurTextIndex);
while not fHighlighter.GetEol do begin
fHighlighter.GetTokenEx(sToken,nTokenLen);
attr := fHighlighter.GetTokenAttribute;
DrawHiLightMarkupToken(attr,sToken,nTokenLen);
fHighlighter.Next;
end;
end;
Then it must iterate the whole line, without a gap.
Based on that, it should be possible to improve the position highlighter.
Also you only need to create one attr of yourself:
Attr1:=Highlighter.CreateTokenID('Attr1',clRed,clNone,[]);
// Line 1, up to col 3
Highlighter.AddToken(1,3,tkText);
// Line 1, up to col 7
Highlighter.AddToken(1,7,Attr2);
I will update the example