From 928d24e82e35632e07bcb34fde50def9d1f90b2e Mon Sep 17 00:00:00 2001 From: David Poeschl Date: Mon, 4 May 2015 21:45:06 -0700 Subject: [PATCH] Add global undo to ContainedLanguageCodeSupport.TryRenameElement Fixes internal TFS bug #1035934 "Undo didn't work in code file after rename control's ID in properties" Wrap the contents of ContainedLanguageCodeSupport,.TryRenameElement in a global undo. This allows the undo of a rename done from the aspx designer (for example) to correctly revert the C#/VB part of the rename as well. --- .../Venus/ContainedLanguageCodeSupport.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguageCodeSupport.cs b/src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguageCodeSupport.cs index 50befd79ea9..8e64f89d384 100644 --- a/src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguageCodeSupport.cs +++ b/src/VisualStudio/Core/Def/Implementation/Venus/ContainedLanguageCodeSupport.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.Editor; using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; +using Microsoft.CodeAnalysis.Editor.Undo; using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Formatting.Rules; using Microsoft.CodeAnalysis.Host; @@ -314,18 +315,24 @@ public static string GetEventHandlerMemberId(Document document, string className var newSolution = Renamer.RenameSymbolAsync(document.Project.Solution, symbol, newName, optionSet, cancellationToken).WaitAndGetResult(cancellationToken); var changedDocuments = newSolution.GetChangedDocuments(document.Project.Solution); - // Notify third parties about the coming rename operation on the workspace, and let - // any exceptions propagate through - refactorNotifyServices.TryOnBeforeGlobalSymbolRenamed(workspace, changedDocuments, symbol, newName, throwOnFailure: true); - - if (!workspace.TryApplyChanges(newSolution)) + var undoTitle = string.Format(EditorFeaturesResources.RenameTo, symbol.Name, newName); + using (var workspaceUndoTransaction = workspace.OpenGlobalUndoTransaction(undoTitle)) { - Exceptions.ThrowEFail(); - } + // Notify third parties about the coming rename operation on the workspace, and let + // any exceptions propagate through + refactorNotifyServices.TryOnBeforeGlobalSymbolRenamed(workspace, changedDocuments, symbol, newName, throwOnFailure: true); - // Notify third parties about the completed rename operation on the workspace, and - // let any exceptions propagate through - refactorNotifyServices.TryOnAfterGlobalSymbolRenamed(workspace, changedDocuments, symbol, newName, throwOnFailure: true); + if (!workspace.TryApplyChanges(newSolution)) + { + Exceptions.ThrowEFail(); + } + + // Notify third parties about the completed rename operation on the workspace, and + // let any exceptions propagate through + refactorNotifyServices.TryOnAfterGlobalSymbolRenamed(workspace, changedDocuments, symbol, newName, throwOnFailure: true); + + workspaceUndoTransaction.Commit(); + } RenameTrackingDismisser.DismissRenameTracking(workspace, changedDocuments); return true; -- GitLab