Visual Studio DTE2: How to Get the Text Content of the Current Document

I developed a package for Visual Studio extension. As part of this, I have a context menu that should handle all the text content of the active document (HTML editor).

I understand how to get the current selection: TextSelection txtSelection = (TextSelection) _bllManager.CurrentDocument.Selection;

But I don’t understand how to get all the content of the code window in case nothing is selected.

I am currently using work-around by doing txtSelection.SelectAll (), but it moves the cursor and I don't want this.

Any suggestion?

Thanks.

+4
source share
1 answer

This 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); 
+4
source

Source: https://habr.com/ru/post/1306487/


All Articles