Skip to content

Confirm before discarding pull request creation with unsaved changes#8796

Draft
alexr00 with Copilot wants to merge 6 commits into
mainfrom
copilot/confirmation-popup-for-cancel-button
Draft

Confirm before discarding pull request creation with unsaved changes#8796
alexr00 with Copilot wants to merge 6 commits into
mainfrom
copilot/confirmation-popup-for-cancel-button

Conversation

Copilot AI commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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:

  • A title that has been manually edited (differs from the default derived from the branch name or latest commit message)
  • A description that differs from the loaded template (template-only contents do not prompt, since templates are easy to restore)
  • Any selected labels, assignees, reviewers, projects, or a milestone

Details:

  • Setting — adds githubPullRequests.showPullRequestCancelConfirmation (boolean, default true) as the persistent "never show again" state.
  • Types — adds CancelCreatePullRequestNew in common/views.ts, extending CreatePullRequestNew with a hasUnsavedChanges: boolean flag.
  • WebviewcancelCreate in createContextNew.ts computes hasUnsavedChanges from the current createParams (comparing pendingTitle/pendingDescription to 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 on cancelled === true, so a declined dialog (or missing reply) preserves the in-progress data.
  • Extensioncancel() in createPRViewProvider.ts shows vscode.window.showWarningMessage({ modal: true, detail: 'Your unsaved changes to this pull request will be lost.' }, 'Discard', 'Don\'t Ask Again') when hasUnsavedChanges is true and the setting is enabled. Choosing Don't Ask Again flips the setting to false; dismissing the modal aborts the cancel. The handler replies with { cancelled: boolean }.

Cancels with no unsaved changes still proceed immediately with no prompt.

Copilot AI and others added 2 commits June 16, 2026 09:04
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
…ail wording

Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot AI changed the title [WIP] Add confirmation popup for Cancel button in pull request creation Confirm before discarding pull request description on Cancel Jun 16, 2026
Copilot AI requested a review from alexr00 June 16, 2026 09:06
@HebaruSan

Copy link
Copy Markdown

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:

  1. In addition to filling in a description, the user might also choose labels. This should probably also be considered an unsaved change and trigger the prompt if present.
  2. The text in the description might be filled in from a template (maybe from this extension itself and maybe from the remote repository) rather than user-entered. If this happens, it would be nice if you could only show the confirmation prompt if the user has made changes, since a template is easy to restore.
  3. Similar to both of the above, the title field always defaults in, either with the branch name or the latest commit message. If the user makes a change to this manually, it would be nice for the confirmation prompt to appear in that case as well, even if the description and labels are blank.
  4. I don't use the assignees, reviewers, milestones, or projects features, but I would guess that people who do use them would appreciate being prompted whether they want to lose that data as well.

@alexr00

alexr00 commented Jun 19, 2026

Copy link
Copy Markdown
Member

Thanks for looking at this @HebaruSan! I haven't had a chance to yet.

@copilot , address these comments:

  1. In addition to filling in a description, the user might also choose labels. This should probably also be considered an unsaved change and trigger the prompt if present.
  2. The text in the description might be filled in from a template (maybe from this extension itself and maybe from the remote repository) rather than user-entered. If this happens, it would be nice if you could only show the confirmation prompt if the user has made changes, since a template is easy to restore.
  3. Similar to both of the above, the title field always defaults in, either with the branch name or the latest commit message. If the user makes a change to this manually, it would be nice for the confirmation prompt to appear in that case as well, even if the description and labels are blank.
  4. I don't use the assignees, reviewers, milestones, or projects features, but I would guess that people who do use them would appreciate being prompted whether they want to lose that data as well.

…eviewers, projects, milestone

Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for looking at this @HebaruSan! I haven't had a chance to yet.

@copilot , address these comments:
...

Addressed in 5b6022a. The dirty check now triggers the confirmation when any of the following has unsaved changes:

  • Title was manually edited (differs from the default derived from branch/commit)
  • Description differs from the loaded template (template-only contents still cancel without prompting)
  • Any labels, assignees, reviewers, projects, or a milestone are set

The setting description and modal detail were updated to reflect the broader scope.

Copilot AI changed the title Confirm before discarding pull request description on Cancel Confirm before discarding pull request creation with unsaved changes Jun 19, 2026
@HebaruSan

Copy link
Copy Markdown

Addressed in 5b6022a

The changes look good, but did @copilot hallucinate this commit hash? It's not in the list of commits, and the URL for it is a 404: 5b6022a

image

@HebaruSan

Copy link
Copy Markdown

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!

@alexr00 alexr00 marked this pull request as ready for review July 16, 2026 10:11
Copilot AI review requested due to automatic review settings July 16, 2026 10:11
@alexr00 alexr00 enabled auto-merge (squash) July 16, 2026 10:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 hasUnsavedChanges flag 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

Comment on lines +112 to +113
const titleEdited = !!params.pendingTitle && params.pendingTitle !== params.defaultTitle;
const descriptionEdited = !!params.pendingDescription && params.pendingDescription !== params.defaultDescription;
Comment on lines 589 to +592
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 });
Comment thread package.json
@alexr00 alexr00 marked this pull request as draft July 16, 2026 10:25
auto-merge was automatically disabled July 16, 2026 10:25

Pull request was converted to draft

@alexr00 alexr00 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot address the unresolved PR comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants