Show prompt in issue reporter when writing to clipboard, fixes #50659

This commit is contained in:
Rachel Macfarlane
2019-05-23 10:46:05 -07:00
parent 1e54e7f4cb
commit 52ee044787
2 changed files with 40 additions and 5 deletions

View File

@@ -440,11 +440,11 @@ export class IssueReporter extends Disposable {
}
});
document.onkeydown = (e: KeyboardEvent) => {
document.onkeydown = async (e: KeyboardEvent) => {
const cmdOrCtrlKey = platform.isMacintosh ? e.metaKey : e.ctrlKey;
// Cmd/Ctrl+Enter previews issue and closes window
if (cmdOrCtrlKey && e.keyCode === 13) {
if (this.createIssue()) {
if (await this.createIssue()) {
ipcRenderer.send('vscode:closeIssueReporter');
}
}
@@ -843,7 +843,7 @@ export class IssueReporter extends Disposable {
return isValid;
}
private createIssue(): boolean {
private async createIssue(): Promise<boolean> {
if (!this.validateInputs()) {
// If inputs are invalid, set focus to the first one and add listeners on them
// to detect further changes
@@ -887,14 +887,32 @@ export class IssueReporter extends Disposable {
let url = baseUrl + `&body=${encodeURIComponent(issueBody)}`;
if (url.length > MAX_URL_LENGTH) {
clipboard.writeText(issueBody);
url = baseUrl + `&body=${encodeURIComponent(localize('pasteData', "We have written the needed data into your clipboard because it was too large to send. Please paste."))}`;
try {
url = await this.writeToClipboard(baseUrl, issueBody);
} catch (_) {
return false;
}
}
ipcRenderer.send('vscode:openExternal', url);
return true;
}
private async writeToClipboard(baseUrl: string, issueBody: string): Promise<string> {
return new Promise((resolve, reject) => {
ipcRenderer.once('vscode:issueReporterClipboardResponse', (_: unknown, shouldWrite: boolean) => {
if (shouldWrite) {
clipboard.writeText(issueBody);
resolve(baseUrl + `&body=${encodeURIComponent(localize('pasteData', "We have written the needed data into your clipboard because it was too large to send. Please paste."))}`);
} else {
reject();
}
});
ipcRenderer.send('vscode:issueReporterClipboard');
});
}
private getExtensionGitHubUrl(): string {
let repositoryUrl = '';
const bugsUrl = this.getExtensionBugsUrl();