Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain the look and feel of the result grid in copy/paste #8072

Merged
merged 2 commits into from
Oct 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/sql/platform/query/common/gridDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export interface IGridDataProvider {
}

export async function getResultsString(provider: IGridDataProvider, selection: Slick.Range[], includeHeaders?: boolean): Promise<string> {
let headers: Map<Number, string> = new Map(); // Maps a column index -> header
let rows: Map<Number, Map<Number, string>> = new Map(); // Maps row index -> column index -> actual row value
let headers: Map<number, string> = new Map(); // Maps a column index -> header
let rows: Map<number, Map<number, string>> = new Map(); // Maps row index -> column index -> actual row value
const eol = provider.getEolString();

// create a mapping of the ranges to get promises
let tasks = selection.map((range, i) => {
return async () => {
let tasks: (() => Promise<void>)[] = selection.map((range) => {
return async (): Promise<void> => {
let startCol = range.fromCell;
let startRow = range.fromRow;

Expand Down Expand Up @@ -88,22 +88,24 @@ export async function getResultsString(provider: IGridDataProvider, selection: S
};
});

if (tasks.length > 0) {
let p = tasks[0]();
for (let i = 1; i < tasks.length; i++) {
p = p.then(tasks[i]);
}
await p;
}
// Set the tasks gathered above to execute
let actionedTasks: Promise<void>[] = tasks.map(t => { return t(); });

// Make sure all these tasks have executed
await Promise.all(actionedTasks);
abist marked this conversation as resolved.
Show resolved Hide resolved

const sortResults = (e1: [number, any], e2: [number, any]) => {
return e1[0] - e2[0];
};
headers = new Map([...headers].sort(sortResults));
rows = new Map([...rows].sort(sortResults));

let copyString = '';
if (includeHeaders) {
copyString = [...headers.values()].join('\t').concat(eol);
}

const rowKeys = [...headers.keys()].sort();

rows = new Map([...rows.entries()].sort());
const rowKeys = [...headers.keys()];
for (let rowEntry of rows) {
let rowMap = rowEntry[1];
for (let rowIdx of rowKeys) {
Expand Down