我想实现一个Visual Studio 2015扩展,以在代码编辑器中获取用户选择的文本。比我想操纵选定的文本。
在代码编辑器中通过上下文菜单具有“按钮/命令”。但是我不知道如何获取选定的文本。
我认为,这个解决方案在这里已经过时或者我missunderstand解决方案。
我假设您的代码已经在从派生的类中Package
。
您可以像这样获取和修改选择文本:
DTE dte = (DTE)GetService(typeof(DTE));
if (dte.ActiveDocument != null)
{
var selection = (TextSelection)dte.ActiveDocument.Selection;
string text = selection.Text;
// Modify the text, for example:
text = ">>" + text + "<<";
// Replace the selection with the modified text.
selection.Text = text;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句