Created
December 17, 2012 18:29
-
-
Save anonymous/4320643 to your computer and use it in GitHub Desktop.
Get the text of an ITextViewLine as it appears in the user editable document
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