-
-
Save jaredpar/4320875 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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