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

Fix copy/paste of unicode results on Mac #1067

Merged
merged 2 commits into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions src/controllers/queryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,15 @@ export default class QueryRunner {
p = p.then(tasks[i]);
}
p.then(() => {
let oldLang: string;
if (process.platform === 'darwin') {
oldLang = process.env['LANG'];
process.env['LANG'] = 'en_US.UTF-8';
}
ncp.copy(copyString, () => {
if (process.platform === 'darwin') {
process.env['LANG'] = oldLang;
}
resolve();
});
});
Expand Down
26 changes: 20 additions & 6 deletions test/queryRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ suite('Query Runner tests', () => {
'3' + TAB + '4' + CLRF +
'5' + TAB + '6' + CLRF +
'7' + TAB + '8' + CLRF +
'9' + TAB + '10';
'9' + TAB + '10';

const finalStringWithHeader = 'Col1' + TAB + 'Col2' + CLRF + finalStringNoHeader;

Expand All @@ -517,10 +517,11 @@ suite('Query Runner tests', () => {
[{isNull: false, displayValue: '3'}, {isNull: false, displayValue: '4'}],
[{isNull: false, displayValue: '5'}, {isNull: false, displayValue: '6'}],
[{isNull: false, displayValue: '7'}, {isNull: false, displayValue: '8'}],
[{isNull: false, displayValue: '9'}, {isNull: false, displayValue: '10'}]
[{isNull: false, displayValue: '9'}, {isNull: false, displayValue: '10'}]
]
}
};
process.env['LANG'] = 'C';

let testRange: ISlickRange[] = [{fromCell: 0, fromRow: 0, toCell: 1, toRow: 4}];

Expand Down Expand Up @@ -570,7 +571,7 @@ suite('Query Runner tests', () => {
);
queryRunner.uri = testuri;
return queryRunner.copyResults(testRange, 0, 0).then(() => {
let pasteContents = ncp.paste();
let pasteContents = pasteCopiedString();
assert.equal(pasteContents, finalStringNoHeader);
});
});
Expand All @@ -593,7 +594,7 @@ suite('Query Runner tests', () => {
// Call handleResult to ensure column header info is seeded
queryRunner.handleQueryComplete(result);
return queryRunner.copyResults(testRange, 0, 0).then(() => {
let pasteContents = ncp.paste();
let pasteContents = pasteCopiedString();
assert.equal(pasteContents, finalStringWithHeader);
});
});
Expand All @@ -618,7 +619,7 @@ suite('Query Runner tests', () => {

// call copyResults with additional parameter indicating to include headers
return queryRunner.copyResults(testRange, 0, 0, true).then(() => {
let pasteContents = ncp.paste();
let pasteContents = pasteCopiedString();
assert.equal(pasteContents, finalStringWithHeader);
});
});
Expand All @@ -643,7 +644,7 @@ suite('Query Runner tests', () => {

// call copyResults with additional parameter indicating to not include headers
return queryRunner.copyResults(testRange, 0, 0, false).then(() => {
let pasteContents = ncp.paste();
let pasteContents = pasteCopiedString();
assert.equal(pasteContents, finalStringNoHeader);
});
});
Expand Down Expand Up @@ -676,3 +677,16 @@ function setupStandardQueryNotificationHandlerMock(testQueryNotificationHandler:
assert.equal(u, standardUri);
});
}

function pasteCopiedString(): string {
let oldLang: string;
if (process.platform === 'darwin') {
oldLang = process.env['LANG'];
process.env['LANG'] = 'en_US.UTF-8';
}
let pastedString = ncp.paste();
if (process.platform === 'darwin') {
process.env['LANG'] = oldLang;
}
return pastedString;
}