Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I keep track of editor modifications and line position changes in the IDE?

I am writing an IDE plugin that tracks specific lines - consider it similar to the IDE's inbuilt bookmark functionality. When a user edits source code, the position of a specific line changes - what might have been line 100 becomes line 101 when Enter is pressed somewhere above it, for example. Users can also delete lines, select and delete multiple chunks at once, paste in large chunks of text, etc, all of which shifts code around.

I would like to track line insertions and deletions in order to know that "line 100" becomes, say, "line 101", then "line 102", and so forth. How is this possible?


The closest solution I have found so far is using INTAEditServicesNotifier.EditorViewModified which would give access to the entire buffer each time a modification was made. The entire buffer could then be diff-ed with a stored copy of the previous buffer to see what changes there are, and to see how many newlines were added or removed and where.

This is an enormous amount of overhead per editor modification, and there must be better way.

like image 758
David Avatar asked Nov 17 '25 20:11

David


1 Answers

I know this question has been asked 10 years ago, but as it is still unanswered, I just want to give a decent answer valid for Delphi 5 and above (can't check for older ones).

The IOTAEditorBuffer interface provides a function GetEditLineTracker returning an interface IOTAEditLineTracker. You need to register an IOTAEditLineNotifier in the line tracker via AddNotifier to get notified when a tracked line has changed. Call the line trackers AddLine method to track a line. You can give an arbitrary Integer value as second parameter to that call, which will be forwarded to the notifier when triggered.

like image 127
Uwe Raabe Avatar answered Nov 20 '25 14:11

Uwe Raabe