Is there an equivalent for DocumentLine.Tag in the new version?

SyntaxEditor for Windows Forms Forum

Posted 8 months ago by Marc Beeson - Precision Mining
Version: 20.1.0400
Avatar

In the old version we store data (not related to the underlying syntax language) that was associated with a line on the DocumentLine.Tag. In the new version, ITextSnapshotLine has Tag property. We can build up a Dictionary to lookup associated data, but if a line is added or removed, the Dictionary becomes out of sync. Is there a way to associate data with a ITextSnapshotLine?

Comments (2)

Answer - Posted 8 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Marc,

In the new version, we have a better object model where documents track their state via snapshots.  Each snapshot is an immutable copy of the document at that time, which allows full document text to be traversed across threads.  And it allows translating offsets from the current location back to a previous location and vice versa, which is useful when you have things like an AST based on an earlier snapshot.  With the newer snapshot mechanism, document lines are no longer tracked like they were before when there were no snapshots, so storing tags isn't really possible.

I would recommend that you use something like a List<T> where each entry is for the related line index.  Then watch the document's TextChanged event.  It tells you how many lines were inserted/deleted and the start line index.  You can adjust your collection using that information.  If you store that list in the document.Properties dictionary, you can access it from anywhere.


Actipro Software Support

Posted 8 months ago by Marc Beeson - Precision Mining
Avatar

Using the document TextChanged event, I have a satisfactory implementation for tracking line tags. Cheers.

The latest build of this product (v2020.1 build 0402) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.