Visual Studio Development Bookmark and Share   
 index > Visual Studio Extensibility > Edit.FormatDocument does not work inside of UndoContext
 

Edit.FormatDocument does not work inside of UndoContext

VS2008 / Windows XP - both with all service-packs

When the macros I write modify the source-code I put those modifications inside an UndoContext so that a single Undo will revert the source to the state it was in prior to the macro's execution.

In the following macro:
'=========
    ' Insert an 'else'-clause around the next line
    '
    Sub InsertElse1()

        Dim ep1 As EnvDTE80.EditPoint2 = CreateEditPoint()

        DTE.UndoContext.Open("")

        Try
            ep1.StartOfLine()
            ep1.Insert("else{")
            ep1.LineDown(1)
            ep1.EndOfLine()
            ep1.Insert("}")
            DTE.ExecuteCommand("Edit.FormatDocument")

        Finally

            DTE.UndoContext.Close()
        End Try
    End Sub
'============
the Edit.FormatDocument command does nothing; but when I remove the UndoContext it works as expected.

My work-around is to move the Edit.FormatDocument to after the 'End Try' - but then I need to do 2 Undo's to revert the macro's changes.


lms07424  Friday, October 16, 2009 12:37 AM

Hello, Sir
Is some error exits in the task List bar when you use Edit.FormatDocument to format your code.
I have invested your problem, and please note that the Edit.FormatDocument will not work if there is some errors exits in the taskList window. For it could not identity the code element(variable, class, etc), so it does not now where to put the code element.
If I misunderstood you, feel free to let me know.
Thanks
Chao

Chao Kuo  2 hours 42 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• SatelliteDllPath-Option does not work in VS 2005 Beta 1
• Creating a Tool bar
• How to parse 'Event' type with parameter in a Visual Basic code using code model APIs?
• DSL: Mutliple View & Domain Relationships (Reference)
• How do I add new platform targets to VS2005 for vc++
• How to get existing ToolBox Items in C#
• Is it possible to get the DTE2 com object when starting devenv.exe with parameters...?
• Server explorer,drag and drop
• DSL Crashes Visual Studio
• Cannot get IVsCodeWindow from 'docCookie'