Skip to content

fix: confirm before discarding non-empty comment draft on Escape#415

Merged
tomasz-tomczyk merged 1 commit intomainfrom
esc-confirm-discard
May 1, 2026
Merged

fix: confirm before discarding non-empty comment draft on Escape#415
tomasz-tomczyk merged 1 commit intomainfrom
esc-confirm-discard

Conversation

@tomasz-tomczyk
Copy link
Copy Markdown
Owner

@tomasz-tomczyk tomasz-tomczyk commented May 1, 2026

Summary

  • Esc on a non-empty comment form now prompts Discard comment? instead of silently throwing away the draft. Empty form → silent close (unchanged).
  • Cancel button discards immediately (matches GitHub).
  • Ports the same behavior shipped to crit-web for parity.

Test plan

🤖 Generated with Claude Code

Pressing Escape on a comment form silently threw away whatever was in
the textarea. After typing a long comment, a single fat-fingered Esc
would lose it.

Now, if the form's textarea has any non-whitespace content, Escape
surfaces a native window.confirm("Discard comment?"). Empty forms close
silently as before. The Cancel button is left untouched — it's an
explicit, labeled discard action and matches GitHub's behavior.

Programmatic close paths (closeEmptyForms / closeEmptyReviewForm after a
successful submit) bypass the prompt because they only fire when the
textarea is already empty.

Esc gating is applied at:
  - Esc inside textarea (createCommentFormUI's bindSubmitCancelKeys path)
  - Esc with no textarea focus (top-level keydown switch)
Both inline-comment forms and the review-level comment form are covered.

Reply textarea Esc was already correct (only collapses when empty).

E2E coverage:
  - 3 new keyboard.spec.ts tests: Esc cancel/accept dialog flow,
    Cancel-button silent discard (no dialog), empty-form silent close
@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.30%. Comparing base (2ed94fd) to head (c00a3e8).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #415      +/-   ##
==========================================
+ Coverage   67.29%   67.30%   +0.01%     
==========================================
  Files          26       26              
  Lines        9668     9668              
==========================================
+ Hits         6506     6507       +1     
+ Misses       2652     2651       -1     
  Partials      510      510              
Flag Coverage Δ
e2e 34.17% <ø> (-0.14%) ⬇️
unit 63.50% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tomasz-tomczyk tomasz-tomczyk merged commit 44df509 into main May 1, 2026
8 checks passed
@tomasz-tomczyk tomasz-tomczyk deleted the esc-confirm-discard branch May 1, 2026 15:42
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.

1 participant