SynEdit Internals

This is an old revision of SynEdit Internals, edited by Martin at . The current revision is 150401.

Created page with "= TLazEditLineItems (Internal storage) = This class is not part of the SynEdit user interface. It is internally used to organise storage. The class is primarily used by SynEdit's TextBuffer and Highlighter, to store the data for each string and associated data. * TLazEditLineItems ** is an abstract base class and can hold any data. ** can be used to manage a list of dependent child lists (child-lists have an "line item" for each item in the parent, insert/delete ar..."

TLazEditLineItems (Internal storage)

This class is not part of the SynEdit user interface. It is internally used to organise storage. The class is primarily used by SynEdit's TextBuffer and Highlighter, to store the data for each string and associated data.

TLazEditLineItems needs to be sub-classed. This can be done with the provided generic classes, based on LazListClasses.

If data needs initializing, or rec-count handling (managed types) then this can be done using TLazListAspectMemInit.... For example:

  TMyStorage = class(
    specialize TGenLazEditLineItemsFixedShiftList<
      AnsiString,  
      specialize TLazListAspectMemInitManagedRefCnt<AnsiString>  
    >
  )

TLazEditChildLineItemsList (dependent children-list)

Some classes (like highlighters) need to store their own data for each LineItem it the SynEdit's TextBuffer. For this they add their storage list to the TLazEditChildLineItemsList provided by the TextBuffer (property Range).

The list will forward calls of the parent to each child:

The parent can be implemented using the generic TGenLazEditParentLineItems

Example (TextBuffer / Highlighter)

SynEdits TextBuffer uses such a list to store for each line: - The string for each line - The "object" (as given by user-code via SynEdit.Lines.Object[i]) - Flags (line modified)

It provides a

    property Ranges[Index: Pointer]: TLazEditLineItems read GetRange write PutRange;

through which other code can add their own child-lists. "Index" must be a unique ID. Callers can e.g. use "Pointer(self)".

Such child-lists are registered by the Highlighter to keep per line state. (This is where the name "Ranges" was originally introduced: https://wiki.freepascal.org/SynEdit_Highlighter#Step_2:_Using_Ranges ). The can also be used by other code. E.g. SynEdit keeps a list for managing tab (#9) info per line.

Changes in 4.99

Before 4.99 the data was stored in (Old => New)

The old classes were overly complex. The forced user-code to deal with several steps (capacity, count, move) for an insert. The old classes did not manage any initialisation, each class had to take care to manage ref-counts on managed types.

For 5.0 the classes provide a compatibility layer providing methods matching the old interface and functionality. The compatibility methods are marked deprecated and will be removed in 5.99

  • InsertRows / DeleteRows: (New names Insert/Delete)

Old: Used to Call: Capacity, Count, Move. Required user-code to handle ref-counts of managed data

New: No longer call any of those methods. Handling of Managed data is done by the "MemInit" of LazListClasses

  • Count

Old: read/write

New: read/only. Call insert/delete as appropriate

  • Capacity

Old: was called when internally changed

New: internal capacity changes are not notified (can be done by using the callback capacity in LazListClasses)

  • Same changes as in TSynEditStorageMem
  • TLazEditChildLineItemsList now calls: Insert/Delete/Move/Capacity

(Move and Capacity, only if Move on the parent was called by user-code / Capacity may change on its own)

  • TLazEditChildLineItemsList now calls: TextChanged (triggered by calling CallLineTextChanged in the parent)
  • Helper for implementing a parent / previously had to be done in each parent.
  • Custom subclasses need to follow the above rules
  • Some properties/methods were renamed (they should only be needed in the Highlighter base class / subclasses should rarely be affected)

procedure ClearReScanNeeded now called ValidateAll

procedure AdjustReScanStart now called UpdateFirstInvalidLine

property NeedsReScanStartIndex now called FirstInvalidLine

property NeedsReScanEndIndex now called LastInvalidLine

property NeedsReScanRealStartIndex now called UnsentValidationStartLine