Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:01:02+00:00 2026-06-04T10:01:02+00:00

I have created VSPackage that provides certain functionality in Visual Studio code window context

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:01:03+00:00Added an answer on June 4, 2026 at 10:01 am

    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:

    class NavigateListener: IVsRunningDocTableEvents3
    {
        private HashSet<IVsTextView> views = new HashSet<IVsTextView>();
        private IVsRunningDocumentTable table;
        private uint cookie;
    ...
    

    Outside, call this register call — add an unregister call that unadvises the events.

    public void Register()
    {
        table =(IVsRunningDocumentTable)    Package.GetGlobalService(typeof(SVsRunningDocumentTable));
        // Listen to show/hide events of docs to register activate/deactivate cursor  listeners.
        table.AdviseRunningDocTableEvents(this, out cookie);
    }
    

    The running table has lots of events, like save, etc, but you can listen to when a view is registered:

    public int OnAfterDocumentWindowHide(uint docCookie, IVsWindowFrame pFrame)
    {
        IVsTextView view = VsShellUtilities.GetTextView(pFrame);
        if (view != null)
        {
            views.Add(view);
        }
    }
    

    You may have trouble with documents that had changes saved but then were closed… remove them for now…

    public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
    {
        IVsTextView view = VsShellUtilities.GetTextView(pFrame);
        if (view != null)
        {
            views.Remove(view);
        }
        return VSConstants.S_OK;
    }
    

    Then you can do a super undo nuke. I haven’t testing this part — you’ll have to play with it.

    private void NukeFromOrbit()
    {
        foreach( var view in views )
        {
            IVsTextLines buffer;
            view.GetBuffer(out buffer);
            IOleUndoManager manager;
            buffer.GetUndoManager(out manager);
            IEnumOleUndoUnits units;
            manager.EnumUndoable(out units);
            uint fetched=0;
            var unitArray = new IOleUndoUnit[1];
            while( units.Next(1, unitArray , out fetched ) == VSConstants.S_OK)
            {
                unitArray[0].Do(manager);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a VSPackage for Visual Studio 2008 that I created for adding some
Have created a custom navigation menu in wordpress that has some pages and some
I have created a template for Visual Studio 2008 and it currently shows up
I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a sample c++ project under Visual Studio 2010 with following files.
I have created a mini installer in NSIS that installs patches for my application.
Have created simple Ajax enabled contact forms before that have around 12 fields -
I have created a module in Magento which takes certain views from customers about
I have created some forms using zendframework on my local machine that send the
I have created a tab-pane using HAML as shown in my code snippet below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.