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

SyntaxEditor for Windows Forms Forum

The latest build of this product (v2020.1 build 0400) was released 3 months ago, which was before this thread was created.
Posted 23 days ago by Marc
Version: 20.1.0400

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 22 days ago by Actipro Software Support - Cleveland, OH, USA

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 22 days ago by Marc

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

Add Comment

Please log in to a validated account to post comments.