What is the difference between ITrackingPoint, ITrackingSpan, SnapshotPoint, SnapshotSpan, ITextViewLine and when to use?

StackOverflow https://stackoverflow.com/questions/10107152

Question

I'm trying to figure out how to get the visible lines in a IWpfTextView to place a ViewPort and/or Text Adornment based on visible lines.

It seems that these 4 are involved in some way, at least the Spans. And to make sure I understand, a Span is just a series of characters in the TextView right?

Was it helpful?

Solution

IWpfTextView.TextViewLines is the collection of visible lines. In some cases the first and last line might be hidden or partially visible (but 2nd and 2nd-to-last line should be always fully visible). To get the collection of fully visible lines you can use IWpfTextView.TextViewLines.FirstVisibleLine and IWpfTextView.TextViewLines.LastVisibleLine, or filter the collection by ITextViewLine.VisibilityState == VisibilityState.FullyVisible.

A Span is a struct to wrap a start position and a length but it doesn't hold the actual text. There are many kinds of spans in VS Editor for different purposes, for example a SnapshotSpan is a span off of an ITextSnapshot, which stores a start position, a length and the snapshot it belongs to.

Edit:

Sorry I missed the question in the title.

A Point refers to a position and a Span refers to a range. Most VS Editor APIs that take one as parameter have overload for the other.

ITrackingPoint and ITrackingSpan are off of ITextBuffer. "Tracking" means they offset/grow/shrink as the text buffer changes. They are snapshot agnostic.

SnapshotPoint and SnapshotSpan are off of ITextSnapshot. They are bound to the ITextSnapshot and are immutable.

ITextViewLine is formatted line for display. Usually you don't need to change it, only getting visual information from it like Height or VisibilityState.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top