Tracking a line of text

SyntaxEditor for WPF Forum

Posted 7 months ago by Jane
Version: 18.1.0
Avatar

Hi,

I am new to using SyntaxEditor and I am wondering if there is a way to track a line of text without having to use line numbers? My use case is I have a tree list view that contains combobox columns. Each row on the tree list view will correspond to a line of text in the syntax editor. I would like to keep track of that line just in case changes were made via the editor or in the combobox so I can update it two way. I also would need to handle added or removed line(s) above the line of text associated with the tree list item.

Thank you so much.

Comments (3)

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

Hi Jane,

Our TextSnapshotRange object stores an ITextSnapshot (an immutable copy of the document at a certain point in time) and start/end offsets (0-based values from the document start).  This documentation topic covers the subject.

If you have a TextSnapshotRange for a line's range of text, then as edits occur and new snapshots are created for the document, you can use the snapshot translation feature to translate the TextSnapshotRange to the new current snapshot and see what its new values are, or if it is deleted.  TextSnapshotRange can tell you its offset range or position (line/char) range, along with the contained text.


Actipro Software Support

Posted 7 months ago by Jane
Avatar

Thank you so much! TextSnapshotRange worked really well. So far, the only issue I'm having now is if I hit enter/next line at the end of the snapshot range, the snapshot translation moves the text range to the next line. Is there a way for it to not do that? I tried TextRangeTrackingModes.LineBased and TextRangeTrackingModes.Default and both has same behaviour.

TextSnapshotRange translatedRange = selectedItem.TextSnapshot.TranslateTo(this.actiproEditor.Document.CurrentSnapshot, TextRangeTrackingModes.LineBased);
Posted 7 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

When you made the TextSnapshotRange for the line, did it include the line terminator character at the end?  If so, then I would expect the behavior you're seeing since pressing Enter at the end of the visible text (but before the line terminator character) would be in the "middle" of the text range.  Some of the tracking mode options for expanding at the end wouldn't make a difference in that scenario.


Actipro Software Support

The latest build of this product (v22.1.3) was released 20 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.