From dbcb156816b6f9e122444aeaa131456c60580200 Mon Sep 17 00:00:00 2001 From: Hai Cao Date: Tue, 27 Jun 2023 10:18:57 -0700 Subject: [PATCH] Add an option for copying with trailing line break in STS (#2122) --- .../QueryExecution/Contracts/CopyResultsRequest.cs | 5 +++++ .../QueryExecution/QueryExecutionService.cs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Contracts/CopyResultsRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Contracts/CopyResultsRequest.cs index f89a5825..d1e45d64 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Contracts/CopyResultsRequest.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Contracts/CopyResultsRequest.cs @@ -27,6 +27,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts /// public bool RemoveNewLines { get; set; } + /// + /// Whether to avoid adding a line break between rows during row concatenation for copying result when the previous row already has a trailing line break. + /// + public bool AvoidNewLineAfterTailingLineBreak { get; set; } + /// /// Whether to include the column headers. /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs index 594cdac4..0fc91726 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs @@ -789,7 +789,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution } } // Add line break if this is not the last row in all selections. - if (rowIndex + pageStartRowIndex != lastRowIndex) + if (rowIndex + pageStartRowIndex != lastRowIndex && (!builder.ToString().EndsWith(Environment.NewLine) || !requestParams.AvoidNewLineAfterTailingLineBreak)) { builder.Append(Environment.NewLine); }