I like the way TATSynEdit is architected. It's relatively straightforward and makes a lot of sense. Please see the UML class diagram attached below to see what I mean. There's one area that might benefit from a bit of improvement. Currently, text events are published using the OnLog event handler. The problem is that the event being published does not represent a logical unit of work. Consider the following bit of hypothetical code in an editor using the TATSynEdit component:
Suppose the user now selects the 'a' and replaces it with 'c':
This one action results in two events being fired: One that deletes the original line and a second that sets the line to the modified content, but the logical unit of work is that 'a' has been replaced with 'c'.
Instead, if we have an OnLog event as follows OnLog(set_TextReplaced, 100, 3, 1, 1, 'a','c'), where set_TextReplaced is a value in a StringEventType enumeration then we would be able to react to the logical unit of work. This would be more efficient and easier to code for.
So, what I am suggesting is to enrich the TATStringsLogEvent as follows:
TATSTringLogEvent = procedure(Sender: TObject; anEventType : StringsEventType;
const aLineIndex, aColdIndex, anInitialLength, aNewLength: integer;
const anInitialText, aNewText: String);
The new event type would then tell us
- eventType: The type of event: set_TextReplaced, set_TextDeleted, set_TextInserted, set_LineSplit, set_LineJoined
- anIndex: The index of a line[. In case of a line break, that is the index of the line being broken. In case of a line merge, that is the index of the line being merged with the previous line.
- aStartCol: The index of the starting column. In case of a line break, that would be the column where the break is happening. In case of a line merge, that is set to 0.
- anInitialLen: the length of the affected text. In case of set_TextReplaced and set_TextDeleted, that's the length of the text being replaced or deleted. Otherwise, it's zero.
- aNewLen: In case of set_TextInserted, set_TextSplit and set_LineJoined, that would be the length of the text inserted, or the portion of the text moved to the new line, or the length of the text that's moving to the previous line.
- anInitialText, aNewText are self explantory
This would then require that this event be fired from outside of SetLine since it is more holistic. It would require changes to the TATStrings class and perhaps to the DoCommand in TATSynEdit. But I don't think those changes are very significant in terms of code. I think I can introduce those changes myself but I don't want to touch this code before I hear back from Alex.
Any thoughts?