提交 eacb1334 编写于 作者: B Balaji Soundrarajan

Merge pull request #2168 from basoundr/fix1944FormatVbOnSave

Dont Force Format VB on save, paste and OnFocusLost
......@@ -246,7 +246,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit
' Did we paste content that changed the number of lines?
If oldVersion.Changes IsNot Nothing AndAlso oldVersion.Changes.IncludesLineChanges Then
Try
_bufferManagerFactory.CreateForBuffer(args.SubjectBuffer).CommitDirty(isExplicitFormat:=True, cancellationToken:=waitContext.CancellationToken)
_bufferManagerFactory.CreateForBuffer(args.SubjectBuffer).CommitDirty(isExplicitFormat:=False, cancellationToken:=waitContext.CancellationToken)
Catch ex As OperationCanceledException
' If the commit was cancelled, we still want the paste to go through
End Try
......@@ -268,7 +268,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit
allowCancel:=True,
action:=Sub(waitContext)
Using transaction = _textUndoHistoryRegistry.GetHistory(args.TextView.TextBuffer).CreateTransaction(VBEditorResources.FormatOnSave)
_bufferManagerFactory.CreateForBuffer(args.SubjectBuffer).CommitDirty(isExplicitFormat:=True, cancellationToken:=waitContext.CancellationToken)
_bufferManagerFactory.CreateForBuffer(args.SubjectBuffer).CommitDirty(isExplicitFormat:=False, cancellationToken:=waitContext.CancellationToken)
' We should only create the transaction if anything actually happened
If transaction.UndoPrimitives.Any() Then
......
......@@ -117,7 +117,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.LineCommit
action:=
Sub(waitContext)
For Each buffer In _view.BufferGraph.GetTextBuffers(Function(b) b.ContentType.IsOfType(ContentTypeNames.VisualBasicContentType))
_commitBufferManagerFactory.CreateForBuffer(buffer).CommitDirty(isExplicitFormat:=True, cancellationToken:=waitContext.CancellationToken)
_commitBufferManagerFactory.CreateForBuffer(buffer).CommitDirty(isExplicitFormat:=False, cancellationToken:=waitContext.CancellationToken)
Next
End Sub)
End Sub
......
......@@ -22,6 +22,22 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.LineCommit
End Using
End Sub
<Fact>
<WorkItem(1944, "https://github.com/dotnet/roslyn/issues/1944")>
<Trait(Traits.Feature, Traits.Features.LineCommit)>
Public Sub DontCommitOnMultiLinePasteWithPrettyListingOff()
Using testData = New CommitTestData(<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>$$
</Document>
</Project>
</Workspace>)
testData.Workspace.Options = testData.Workspace.Options.WithChangedOption(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic, False)
testData.CommandHandler.ExecuteCommand(New PasteCommandArgs(testData.View, testData.Buffer), Sub() testData.EditorOperations.InsertText("Class Program" & vbCrLf & " Sub M(abc As Integer)" & vbCrLf & " Dim a = 7" & vbCrLf & " End Sub" & vbCrLf & "End Class"))
Assert.Equal(" Dim a = 7", testData.Buffer.CurrentSnapshot.GetLineFromLineNumber(2).GetText())
End Using
End Sub
<Fact>
<Trait(Traits.Feature, Traits.Features.LineCommit)>
<WorkItem(545493)>
......@@ -54,6 +70,27 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.LineCommit
End Using
End Sub
<Fact, WorkItem(1944, "https://github.com/dotnet/roslyn/issues/1944")>
<Trait(Traits.Feature, Traits.Features.LineCommit)>
Public Sub DontCommitOnSavePrettyListingOff()
Using testData = New CommitTestData(<Workspace>
<Project Language="Visual Basic" CommonReferences="true">
<Document>
Class Program
Sub M(abc As Integer)
Dim a $$= 7
End Sub
End Class
</Document>
</Project>
</Workspace>)
testData.Workspace.Options = testData.Workspace.Options.WithChangedOption(FeatureOnOffOptions.PrettyListing, LanguageNames.VisualBasic, False)
testData.Buffer.Insert(57, " ")
testData.CommandHandler.ExecuteCommand(New SaveCommandArgs(testData.View, testData.Buffer), Sub() Exit Sub)
Assert.Equal(" Dim a = 7", testData.Buffer.CurrentSnapshot.GetLineFromLineNumber(3).GetText())
End Using
End Sub
<Fact>
<Trait(Traits.Feature, Traits.Features.Formatting)>
<WorkItem(545493)>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册