From fdde123702c400891db1b755e776eb7573fa336d Mon Sep 17 00:00:00 2001 From: David Barbet Date: Mon, 1 Apr 2019 20:54:14 -0700 Subject: [PATCH] Cancel transaction if there is no document to format. --- .../CommentSelection/AbstractCommentSelectionBase.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/Core/Implementation/CommentSelection/AbstractCommentSelectionBase.cs b/src/EditorFeatures/Core/Implementation/CommentSelection/AbstractCommentSelectionBase.cs index e5f3be37e44..f3ce3e64939 100644 --- a/src/EditorFeatures/Core/Implementation/CommentSelection/AbstractCommentSelectionBase.cs +++ b/src/EditorFeatures/Core/Implementation/CommentSelection/AbstractCommentSelectionBase.cs @@ -142,8 +142,15 @@ internal bool ExecuteCommand(ITextView textView, ITextBuffer subjectBuffer, TCom using (var transaction = new CaretPreservingEditTransaction(title, textView, _undoHistoryRegistry, _editorOperationsFactoryService)) { var formattedDocument = Format(service, subjectBuffer.CurrentSnapshot, trackingSnapshotSpans, CancellationToken.None); - formattedDocument?.Project.Solution.Workspace.ApplyDocumentChanges(formattedDocument, CancellationToken.None); - transaction.Complete(); + if (formattedDocument == null) + { + transaction.Cancel(); + } + else + { + formattedDocument.Project.Solution.Workspace.ApplyDocumentChanges(formattedDocument, CancellationToken.None); + transaction.Complete(); + } } } -- GitLab