Visual Studio : exclude outlining from undo/redo stack
Asked Answered
J

6

32

There's something really annoying in Visual Studio : when I expand or collapse a method or code region, this action is pushed on the undo stack. So if I edit some code in a method, then collapse that method, and then want to undo my change, I have to undo twice : once for the collapse action, and once for the change in code. This can be VERY confusing if you expanded or collapsed several things after editing the code, the editor keeps jumping to different places and you don't know whether your changes have been undone or not...

So my question is : is it possible to disable that behavior ? i.e., that only changes in code are taken into account in the undo stack ?

PS: I'm using Visual Studio 2008


If this behavior annoys you too, please vote to fix it!

Jessie answered 29/11, 2009 at 23:12 Comment(0)
D
13

I've created the Disable Outlining Undo extension that excludes expanding and collapsing operations from recording to the undo/redo stack in Visual Studio 2017/2019.

Thanks to Rick Sladkey for the idea!

Dael answered 11/3, 2019 at 7:22 Comment(7)
Nice! Thanks Sergey, I'll give it a try.Jessie
Why not publish it on the VS gallery, though? Is the source available anywhere?Jessie
It is in the gallery. Source code is not available.Dael
Worked perfectly here. Thanks.Beefsteak
This is excellent. Thanks Sergey. Everyone here who downloaded it, please give it a rating in the extension store.Adolfoadolph
@ThomasLevesque did it work? if so, maybe accept the answer?Flittermouse
@Flittermouse to be honest I had completely forgotten about it, and never tried it. Based on the reviews in the store, it seems to work as advertised. I'll install it now.Jessie
D
6

I did a little poking around and discovered that there is in fact an option in Visual Studio to disable this behavior, and yet it does not seem to be exposed anywhere in the user interface. However, you can set it programmatically, and I tested that it does work, so it is (technically) possible.

The options is:

DefaultTextViewOptions.OutliningUndoOptionId

and you set it like this:

textView.Options.SetOptionValue(DefaultTextViewOptions.OutliningUndoOptionId, false);

With this information a very simple Visual Studio extension could be written to toggle this setting for all new ITextView instances.

Drawl answered 22/6, 2018 at 5:28 Comment(1)
Very nice, thanks! I might create such an extension ;)Jessie
E
5

You can vote for fixing it in Visual Studio UserVoice.

Update: original link broken. New link here

Emory answered 21/10, 2013 at 8:30 Comment(2)
Thanks, but I'm aware of that... I'm the one who created this UserVoice entry ;)Jessie
It seems Microsoft have now deleted the Visual Studio UserVoice, unfortunately.Pharr
I
2

I don't believe there is a way to disable this behavior.

As alternatives, the undo and redo toolbar icons have history dropdowns that allow you to visually see a summary of what the recent changes were that you would be undoing or redoing. That can sometimes help to ensure you're undoing (or redoing) what you're expecting.

Since that isn't always enough to know exactly what the changes are (the undo history only displays a summary), the solution I occasionally use to address this is to combine undo (ctrl-z), redo (ctrl-y), and undo again. The first undo moves to where the change happened (and undoes that change). The redo will undo the undo (which essentially repeats the last change made). And the last undo will perform the undo again with the window scrolled to the location where I can actually see the undo happening and can confirm whether that's the change I was expecting to undo. It's not very efficient, but it can be very effective to ensure the code is in state that's really expected.

Indistinctive answered 14/12, 2009 at 21:24 Comment(1)
Indeed I could use the history dropdowns... I'm not so sure about your solution with shortcut keys however, it's not very convenient ;)Jessie
G
1

The best solution I can propose is to disable outlining using CTRL+M, then CTRL+P.

Gisarme answered 10/12, 2009 at 15:51 Comment(1)
No, this is not an option... I really like the code outlining feature, I just don't want it to be part of the undo stackJessie
S
0

First, it seems that not all outlining operations are recorded in the undo/redo stack.

  • Toggle Outlining Expansion (CTRL+M/CTRL+M) is recorded in the stack
  • Toggle All Outlining (CTRL+M/CTRL+L) is recorded in the stack
  • Collapse to definitions (CTRL+M/CTRL+O) is NOT recorded in the stack

So, as far as I know, it is not possible to avoid the recording of Toggle operations in the undo/redo stack in Visual Studio 2008.

The only option you have it to enable/disable outlining for each source type. For C#, outlining can be enabled/disabled in ToolsOptionsText EditorC#Advanced with the Enter outlining mode when files open checkbox.

Sheya answered 15/12, 2009 at 16:41 Comment(2)
Like I said to Cedrik, I don't want to disable outlining... I like it and want to keep itJessie
Then, you will have to deal with undo/redo.Sheya

© 2022 - 2024 — McMap. All rights reserved.