/// <summary> /// Returns a caret location of itself or the location after the token the caret is inside of. /// </summary> private static int GetCaretLocationAfterToken(ITextStructureNavigator navigator, BlockCommentSelectionHelper blockCommentSelection) { var snapshotSpan = blockCommentSelection.SnapshotSpan; if (navigator == null) { return(snapshotSpan.Start); } var extent = navigator.GetExtentOfWord(snapshotSpan.Start); int locationAfterToken = extent.Span.End; // Don't move to the end if it's already before the token. if (snapshotSpan.Start == extent.Span.Start) { locationAfterToken = extent.Span.Start; } // If the 'word' is just whitespace, use the selected location. if (blockCommentSelection.IsSpanWhitespace(TextSpan.FromBounds(extent.Span.Start, extent.Span.End))) { locationAfterToken = snapshotSpan.Start; } return(locationAfterToken); }