I’m developing an extension, and basically need to replace text in current window. I can call ReplacePattern like this
EnvDTE80.DTE2 app = GetActiveIDE();
TextDocument txt = app.ActiveDocument.Object("TextDocument") as TextDocument;
EditPoint ep = txt.CreateEditPoint(txt.StartPoint);
txt.ReplacePattern(".*", string.Empty, (int)vsFindOptions.vsFindOptionsRegularExpression);
ep.Insert("blah");
and it works. The only problem with it is that when user tries to undo the replacement, the text is coming back line-by-line, not as a single big chunk – so I think there should be a better way…
Duh.. This: