ITextSnapshot snapshot = textView.TextSnapshot; SnapshotPoint caretPosition = textView.Caret.Position.BufferPosition; SnapshotSpan selectedSpan = textView.Selection.SelectedSpans.First().SnapshotSpan; if (selectedSpan.Contains(caretPosition)) { // Do something }
ITextSnapshot oldSnapshot = args.OldSnapshot; ITextSnapshot newSnapshot = args.NewSnapshot; SnapshotSpan changedSpan = args.Changes.First().NewSpan; if (mySpan.Contains(changedSpan)) { // Do something with the changed text within the span }In this example, we have made some changes to a text buffer and are checking if the changed text is contained within a specific span. If it is, we can perform some specific action. Both of these examples are using the Visual Studio Text Editor Library, specifically the ITextSnapshot and SnapshotSpan classes.