Question

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...

Was it helpful?

Solution

Duh.. This:

EditPoint ep = txt.CreateEditPoint(txt.StartPoint);
ep.Delete(txt.EndPoint);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top