How do I add a point to the navigation history? (For navigate forward/back) RRS feed

  • Question

  • Say I'm implementing a service in a VSIX extension that, when a command is triggered, moves the cursor to a different location (like Go to Definition does).

    I'd like to add a point to the navigation history so that if the user decides they want to go back to where they were before they triggered the command, they can do so via View→Navigate Backward (Ctrl -).

    So far, I've figured out a way that involves adding one temporary point via IVsUIShell.AddNewBFNavigationItem, then adding another via IVsBackForwardNavigation2 (which seems to only work if AddNewBFNavigationItem was called first), then removing the temporary point. This feels like a hack, and I can't help but wonder if this code will break in future versions of Visual Studio (I'm developing for VS2013, by the way). Is there a better way than this brittle code?

    private static void AddNavigationHistoryPoint(IVsWindowFrame frame)
        object navServiceObj;
        if (frame.GetProperty((int)__VSFPROPID4.VSFPROPID_NavigationInterface, out navServiceObj) == VSConstants.S_OK)
            var navService = navServiceObj as IVsBackForwardNavigation2;
            if (navService != null && UiShell != null)
                if (UiShell.AddNewBFNavigationItem(frame, "", null, 0) == VSConstants.S_OK)

    • Edited by cameron3141 Wednesday, March 5, 2014 5:46 PM
    Wednesday, March 5, 2014 5:44 PM

All replies

  • Hi,

    Thank you for visiting this forum!

    Could you please tell us what extension you create? Could you please provide us with a screenshot?

    Best regards,


    Friday, March 7, 2014 5:28 AM
  • Well, technically it's not a standalone extension -- we're extending the isolated shell. But it works out to the same thing.

    There's nothing to take a screenshot of, since it's just a piece of code that listens for a command and then moves the cursor to a different line.

    How exactly is any of this relevant?

    Friday, March 7, 2014 1:49 PM