Understanding the SynEdit Highlighter
SynEdit - Highlighter relationship
SynEdit <-> Highlighter have a n to 1 relationship.
- 1 (instance of a) Highlighter can serve n (many) (instances of) SynEdits
- Each SynEdit only has one Highlighter
As a result of this:
- no Highlighter Instance has a (fixed) reference to the SynEdit.
- All data for the Highlighter is (and must be) stored on the SynEdit (actually on the TextBuffer of SynEdit (referred to as "Lines").
However SynEdit ensures before each call to the Highlighter that Highlighter.CurrentLines is set to the current SynEdits Lines. This way the highlighter can access the data whenever needed. The Format of the data-storage is determined by the highlighter (TSynCustomHighlighter.AttachToLines)
Scanning and Returning Highlight attributes
The Highlighter is expected to work on a per Line base.
If any text was modified, SynEdit will call (TSynCustomHighlighter.ScanFrom) with the line range. The highlighter should know the state of the previous line.
If Highlight attributes are required SynEdit will request them per Line too (looping through individual tokens on a line)
Also the BaseClass for the highlighters data (see AttachToLines) is based on per line storage, and SynEdits TextBuffer (Lines) do maintenance on this data to keep it synchronized. That is when ever lines of text are inserted or removed, so are entries inserted or removed from the highlighters data (hence it must have one entry per line).
Usually Highlighters store the end-of-line-status in this field. So if the highlighter is going to work on a line, it will continue with the state-entry from the previous line.