mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-04 17:23:45 -05:00
Add a config for copying with trailing line break (#23481)
This commit is contained in:
@@ -46,6 +46,8 @@ export interface IGridDataProvider {
|
||||
|
||||
shouldRemoveNewLines(): boolean;
|
||||
|
||||
shouldSkipNewLineAfterTrailingLineBreak(): boolean;
|
||||
|
||||
getColumnHeaders(range: Slick.Range): string[] | undefined;
|
||||
|
||||
readonly canSerialize: boolean;
|
||||
@@ -101,6 +103,7 @@ export async function copySelectionToClipboard(clipboardService: IClipboardServi
|
||||
const eol = provider.getEolString();
|
||||
const valueSeparator = '\t';
|
||||
const shouldRemoveNewLines = provider.shouldRemoveNewLines();
|
||||
const shouldSkipNewLineAfterTrailingLineBreak = provider.shouldSkipNewLineAfterTrailingLineBreak();
|
||||
|
||||
// Merge the selections to get the unique columns and unique rows.
|
||||
const gridRanges = GridRange.fromSlickRanges(selections);
|
||||
@@ -154,7 +157,9 @@ export async function copySelectionToClipboard(clipboardService: IClipboardServi
|
||||
});
|
||||
}
|
||||
if (!cancellationTokenSource.token.isCancellationRequested) {
|
||||
resultString += rowValues.join(eol);
|
||||
resultString += rowValues.reduce(
|
||||
(prevVal, currVal, idx) => prevVal + (idx > 0 && (!prevVal?.endsWith(eol) || !shouldSkipNewLineAfterTrailingLineBreak) ? eol : '') + currVal,
|
||||
);
|
||||
await clipboardService.writeText(resultString);
|
||||
}
|
||||
}, cancellationTokenSource);
|
||||
|
||||
@@ -465,15 +465,13 @@ export default class QueryRunner extends Disposable {
|
||||
* @param selections The selection range to copy
|
||||
* @param batchId The batch id of the result to copy from
|
||||
* @param resultId The result id of the result to copy from
|
||||
* @param removeNewLines Whether to remove line breaks from values.
|
||||
* @param includeHeaders [Optional]: Should column headers be included in the copy selection
|
||||
*/
|
||||
async copyResults(selections: Slick.Range[], batchId: number, resultId: number, removeNewLines: boolean, includeHeaders?: boolean): Promise<void> {
|
||||
async copyResults(selections: Slick.Range[], batchId: number, resultId: number, includeHeaders?: boolean): Promise<void> {
|
||||
await this.queryManagementService.copyResults({
|
||||
ownerUri: this.uri,
|
||||
batchIndex: batchId,
|
||||
resultSetIndex: resultId,
|
||||
removeNewLines: removeNewLines,
|
||||
includeHeaders: includeHeaders,
|
||||
selections: selections.map(selection => {
|
||||
return {
|
||||
@@ -592,7 +590,7 @@ export class QueryGridDataProvider implements IGridDataProvider {
|
||||
|
||||
private async handleCopyRequestByProvider(selections: Slick.Range[], includeHeaders?: boolean): Promise<void> {
|
||||
executeCopyWithNotification(this._notificationService, selections, async () => {
|
||||
await this.queryRunner.copyResults(selections, this.batchId, this.resultSetId, this.shouldRemoveNewLines(), this.shouldIncludeHeaders(includeHeaders));
|
||||
await this.queryRunner.copyResults(selections, this.batchId, this.resultSetId, this.shouldIncludeHeaders(includeHeaders));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -614,6 +612,9 @@ export class QueryGridDataProvider implements IGridDataProvider {
|
||||
shouldRemoveNewLines(): boolean {
|
||||
return shouldRemoveNewLines(this._configurationService);
|
||||
}
|
||||
shouldSkipNewLineAfterTrailingLineBreak(): boolean {
|
||||
return shouldSkipNewLineAfterTrailingLineBreak(this._configurationService);
|
||||
}
|
||||
getColumnHeaders(range: Slick.Range): string[] | undefined {
|
||||
return this.queryRunner.getColumnHeaders(this.batchId, this.resultSetId, range);
|
||||
}
|
||||
@@ -648,6 +649,12 @@ export function shouldRemoveNewLines(configurationService: IConfigurationService
|
||||
return !!removeNewLines;
|
||||
}
|
||||
|
||||
export function shouldSkipNewLineAfterTrailingLineBreak(configurationService: IConfigurationService): boolean {
|
||||
// get config skipNewLineAfterTrailingLineBreak option from vscode config
|
||||
let skipNewLineAfterTrailingLineBreak = configurationService.getValue<IQueryEditorConfiguration>('queryEditor').results.skipNewLineAfterTrailingLineBreak;
|
||||
return !!skipNewLineAfterTrailingLineBreak;
|
||||
}
|
||||
|
||||
function isRangeOrUndefined(input: string | IRange | undefined): input is IRange | undefined {
|
||||
return Range.isIRange(input) || types.isUndefinedOrNull(input);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user