Skip to content

Instantly share code, notes, and snippets.

@jaredpar
Forked from anonymous/gist:4320643
Created December 17, 2012 18:56
Show Gist options
  • Save jaredpar/4320875 to your computer and use it in GitHub Desktop.
Save jaredpar/4320875 to your computer and use it in GitHub Desktop.
/// <summary>
/// This will get the text of the ITextView line as it appears in the actual user editable
/// document.
/// </summary>
public static bool TryGetText(ITextView textView, ITextViewLine textViewLine, out string text)
{
var extent = textViewLine.Extent;
var bufferGraph = textView.BufferGraph;
try
{
var collection = bufferGraph.MapDownToSnapshot(extent, SpanTrackingMode.EdgeInclusive, textView.TextSnapshot);
var span = new SnapshotSpan(collection[0].Start, collection[collection.Count - 1].End);
text = span.ToString();
return true;
}
catch
{
text = null;
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment