Confirm before discarding pull request creation with unsaved changes#8796
Conversation
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
…ail wording Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
|
Hi @copilot, a few points that may be worth considering if you read comments and react to them, otherwise these are suggestions for reviewer @alexr00:
|
|
Thanks for looking at this @HebaruSan! I haven't had a chance to yet. @copilot , address these comments:
|
…eviewers, projects, milestone Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Addressed in 5b6022a. The dirty check now triggers the confirmation when any of the following has unsaved changes:
The setting description and modal detail were updated to reflect the broader scope. |
|
Hi @alexr00, I realize this may not be in scope, but would it also be possible to make the description text box support Markdown syntax highlighting, like the code editor? If there's a derived class that could just do that as a drop-in replacement, then that would be a pretty tremendous bit of low-hanging fruit, as it would lend visual structure to descriptions with formatting. Thanks again for initiating this! |
There was a problem hiding this comment.
Pull request overview
Adds a safety confirmation when canceling pull request creation if the user has unsaved edits in the create PR webview, with a persisted “don’t ask again” setting to disable the prompt.
Changes:
- Extends the cancel-create request payload with a
hasUnsavedChangesflag computed in the webview. - Shows a modal discard confirmation in the extension when unsaved changes are present (and the setting is enabled), and updates the setting when the user chooses “Don’t Ask Again”.
- Adds a new contributed configuration setting and localization string for controlling the confirmation behavior.
Show a summary per file
| File | Description |
|---|---|
| webviews/common/createContextNew.ts | Computes hasUnsavedChanges and defers clearing persisted webview state until cancellation is confirmed. |
| src/github/createPRViewProvider.ts | Displays modal confirmation on cancel and persists the “don’t ask again” choice; replies with { cancelled: boolean }. |
| src/common/settingKeys.ts | Adds a new setting key constant for the cancel confirmation toggle. |
| package.nls.json | Adds localized description text for the new configuration setting. |
| package.json | Contributes the new githubPullRequests.showCreatePullRequestCancelConfirmation setting. |
| common/views.ts | Introduces CancelCreatePullRequestNew message type with hasUnsavedChanges. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 3
- Review effort level: Low
| const titleEdited = !!params.pendingTitle && params.pendingTitle !== params.defaultTitle; | ||
| const descriptionEdited = !!params.pendingDescription && params.pendingDescription !== params.defaultDescription; |
| this._onDone.fire(undefined); | ||
| // Re-fetch the automerge info so that it's updated for next time. | ||
| await this.getMergeConfiguration(message.args.owner, message.args.repo, true); | ||
| return this._replyMessage(message, undefined); | ||
| return this._replyMessage(message, { cancelled: true }); |
Pull request was converted to draft

Clicking Cancel in the PR creation view immediately discards any in-progress data. This is easy to trigger accidentally (e.g. tabbing from the description field and hitting Space/Enter), losing significant work.
Cancel now shows a modal confirmation when there are unsaved changes, mirroring VS Code's standard discard-changes prompt. Unsaved changes are detected for any of the following:
Details:
githubPullRequests.showPullRequestCancelConfirmation(boolean, defaulttrue) as the persistent "never show again" state.CancelCreatePullRequestNewincommon/views.ts, extendingCreatePullRequestNewwith ahasUnsavedChanges: booleanflag.cancelCreateincreateContextNew.tscomputeshasUnsavedChangesfrom the currentcreateParams(comparingpendingTitle/pendingDescriptionto their defaults and checking labels/assignees/reviewers/projects/milestone) and includes it in the cancel message. It no longer clears persisted state eagerly; it awaits the reply and only resets state oncancelled === true, so a declined dialog (or missing reply) preserves the in-progress data.cancel()increatePRViewProvider.tsshowsvscode.window.showWarningMessage({ modal: true, detail: 'Your unsaved changes to this pull request will be lost.' }, 'Discard', 'Don\'t Ask Again')whenhasUnsavedChangesis true and the setting is enabled. Choosing Don't Ask Again flips the setting tofalse; dismissing the modal aborts the cancel. The handler replies with{ cancelled: boolean }.Cancels with no unsaved changes still proceed immediately with no prompt.