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

1

8

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?

Routine answered 11/4, 2012 at 13:42 Comment(1)
Forgot to actually update. 1. TextViews are not thought of in lines. This is because of outlining, word wrap, etc which differs the TextBuffer from the visual buffer. 2. SnapshotSpan vs SnapshotPoint - Span represents a string of characters. Point, one character. 3. TrackingPoint vs TrackingSpan. Similar to other Point and Span, except used to determine position in ViewPort. I think I'm correct on these. Or at least seems to be moving that way.Routine
H
7

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.

Humpy answered 18/6, 2012 at 23:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.