Sclerosis
Sclerosis

Reputation: 29

Edit current visual studio document/file without write/save

I am working on a visual studio extension where I have to edit the current code open in the code pane. Here is how my file edit code goes:

DTE dTE = Package.GetGlobalService(typeof(DTE)) as DTE;
TextDocument activeDoc = dTE.ActiveDocument.Object() as TextDocument;
string text =
activeDoc.CreateEditPoint(activeDoc.StartPoint).GetText(activeDoc.EndPoint);
string editted = Manipulate(text);            
//File.WriteAllText("File Address", editted); // I don't want to use this

I want to edit the current opened document such that the user will be able to use ctrl+z to revert any changes the extension makes.

Upvotes: 1

Views: 216

Answers (1)

Sergey Vlasov
Sergey Vlasov

Reputation: 27940

CreateEditPoint returns EnvDTE.EditPoint. You can use, for example, EditPoint.Insert or EditPoint.ReplaceText methods to change the document.

Upvotes: 2

Related Questions