Visual Studio DTE2: how to get text content of the current document
I developped a package to extend Visual Studio. As part of it, I have a context menu that must process the whole text content of the active document (HTML editor).
I understand how to get the current selection : TextSelection txtSelection = (TextSelection)_bllManager.CurrentDocument.Selection;
But I dont't understand how to get the whole content o开发者_StackOverflow中文版f the code window in case nothing is selected.
Currently I use a work-around doing txtSelection.SelectAll() but it moves the cursor and I don't want that.
Any suggestion ?
Thanks.
It can be done using edit points:
var document = (TextDocument)_bllManager.CurrentDocument.Object("TextDocument");
var editPoint = document.CreateEditPoint(document.StartPoint);
var text = editPoint.GetText(document.EndPoint);
精彩评论