diff --git a/src/VisualStudio/Core/Impl/RoslynVisualStudioWorkspace.cs b/src/VisualStudio/Core/Impl/RoslynVisualStudioWorkspace.cs index 10ce8e9eba700eac7600e3999f3c58e30cb5a75b..d7621476ee8728b330a493c7c98bca2e7cf08f0c 100644 --- a/src/VisualStudio/Core/Impl/RoslynVisualStudioWorkspace.cs +++ b/src/VisualStudio/Core/Impl/RoslynVisualStudioWorkspace.cs @@ -124,8 +124,22 @@ internal override IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument { // We need to ensure the file is saved, only if a global undo transaction is open var globalUndoService = this.Services.GetService(); - bool needsSave = globalUndoService.IsGlobalTransactionOpen(this); - bool needsUndoDisabled = needsSave && this.Services.GetService().IsGeneratedCode(this.CurrentSolution.GetDocument(hostDocument.Id)); + var needsSave = globalUndoService.IsGlobalTransactionOpen(this); + + var needsUndoDisabled = false; + if (needsSave) + { + if (this.CurrentSolution.ContainsDocument(hostDocument.Id)) + { + // Disable undo on generated documents + needsUndoDisabled = this.Services.GetService().IsGeneratedCode(this.CurrentSolution.GetDocument(hostDocument.Id)); + } + else + { + // Enable undo on "additional documents" or if no document can be found. + needsUndoDisabled = false; + } + } return new InvisibleEditor(ServiceProvider, hostDocument.FilePath, needsSave, needsUndoDisabled); }