If you want to keep current formatting you can use DocumentScript
to apply modifications on AST. It works based in TextLocation
property stored in syntax tree.
To create a script you need to do this :
IDocument document = new StringBuilderDocument("source code");
CSharpFormattingOptions policy = FormattingOptionsFactory.CreateAllman();
var options = new TextEditorOptions();
var script = new DocumentScript(document, policy, options);
Now you can use methods like Replace, Remove, InsertAfter and etc. on you AST. It works with both ast nodes as well as offsets.
It also keeps track of modifications, so you don't have to be worry about conflicts on multiple changes.
For more examples on NRefactory you may wanna also check my blog.