I have created VSPackage that provides certain functionality in Visual Studio code window context menu. This action consists of several code edits plus some stuff around.
The problem is, each of these code edits get added to the undo stack separately. What I want is to handle this action as one atomic unit, i.e. pressing CTRL+Z rollbacks all code edits and everything else (plus of course, places the unit on top of redo stack).
Documentation regarding this topic is extremely poor, the only thing I found is something about IOleParentUndo unit – but I wasn’t succesfull in implementing it.
I use
IVsTextLines.GetUndoManager()
to get the undo manager – that appears to be a good start.
If undo is managed at the document level then you may have to using the RunningDocumentTable to enumerate the tables, get their undo managers, and nuke from orbit:
Outside, call this register call — add an unregister call that unadvises the events.
The running table has lots of events, like save, etc, but you can listen to when a view is registered:
You may have trouble with documents that had changes saved but then were closed… remove them for now…
Then you can do a super undo nuke. I haven’t testing this part — you’ll have to play with it.