feat(web): add create PR and archive thread keybindings - #5443
feat(web): add create PR and archive thread keybindings#5443leo-mathurin wants to merge 1 commit into
Conversation
Adds two commands to the keybindings system: - `git.createPullRequest` (`mod+shift+p`) opens a pull request for the thread's ref. - `thread.archive` (`mod+shift+a`) archives the thread you are looking at. The PR shortcut is deliberately narrower than the "Create PR" menu item. That item accepts unpushed work and pushes first; the shortcut only arms once the ref has nothing left to send, so a stray keypress can never publish commits the user has not pushed yet. This is expressed as a new `gitCanCreatePr` when-clause variable, supplied by the control that already owns the thread's git status. `mod+shift+p` does not collide with `mod+p` (file picker), which matches unshifted only.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Needs human review This PR introduces two new keyboard shortcuts (mod+shift+p for PR creation, mod+shift+a for archiving) that add new user-facing capabilities. While well-tested and the underlying actions exist, new feature additions from a first-time contributor warrant human review. You can customize Macroscope's approvability policy. Learn more. |
What changed
Two new keybinding commands:
whengit.createPullRequestmod+shift+p!terminalFocus && gitCanCreatePrthread.archivemod+shift+a!terminalFocusthread.archivearchives the thread you are currently on and lands you in a new draft in the same project, reusing the existingarchiveThreadaction so the running-turn refusal and the archived-thread refresh behave exactly as they do from the sidebar.git.createPullRequestopens a PR for the thread's ref.Why the PR shortcut is gated
The shortcut is deliberately narrower than the existing "Create PR" menu item. That item accepts unpushed work and offers to commit and push first. A keyboard shortcut that did the same could publish commits the user had not decided to push, from a single mistyped chord.
So the shortcut only arms once the ref has nothing left to send: no working tree changes, an upstream configured,
aheadCountandbehindCountboth zero, no PR already open, and something to propose against the default ref. While work is still uncommitted or unpushed the shortcut does nothing and the user goes through the menu, which explains what it is about to do.This is expressed as a new
gitCanCreatePrwhen-clause variable. It is supplied byGitActionsControl, which already owns the git status for the active thread. Routing the shortcut through the global handler inroutes/_chat.tsxinstead would have needed a second status subscription just to evaluate the gate.aheadOfDefaultCountis optional on the wire, so a server old enough to omit it falls back to "not on the default ref". That keeps the shortcut alive there and lets the server reject the action if the ref turns out to have nothing to propose.Collision check
mod+shift+pdoes not collide withmod+p(file picker), which matches unshifted only. There is a regression test for this.Tests
GitActionsControl.logic.test.ts: the full gate matrix, including each negative branch and the missing-aheadOfDefaultCountfallback.keybindings.test.ts: resolution of both commands, thegitCanCreatePrandterminalFocusgating, and themod+pcollision check.On screenshots
CONTRIBUTING asks for before/after images on UI changes. There is nothing visual to show here: no new UI, no changed layout. The only rendered surface is Settings > Keybindings, which picks both rows up automatically from the existing label derivation, so they read as "Git: Create Pull Request" and "Thread: Archive" with no per-command wiring. Happy to add a short video of the shortcuts firing if that would help.
I read the "not actively accepting contributions" note and did not open an issue first. Close this if it is not wanted, no hard feelings.
Note
Low Risk
Keyboard-only UX on top of existing git and archive flows; PR shortcut is intentionally conservative to avoid accidental publishes.
Overview
Adds two keyboard shortcuts:
mod+shift+prunsgit.createPullRequest, andmod+shift+arunsthread.archiveon the open thread (via existingarchiveThread, with error toasts on failure).The PR shortcut is stricter than the source-control “Create PR” menu: it only arms when
gitCanCreatePris true—clean worktree, upstream in sync (no ahead/behind), no open PR, and commits ahead of the default ref (with a fallback whenaheadOfDefaultCountis missing). Uncommitted or unpushed work leaves the chord inert so a mistype cannot push or open a PR.GitActionsControlowns the listener and suppliesgitCanCreatePrfrom git status already loaded there;_chat.tsxis not used for this command.Defaults, contract command IDs, user docs, and tests cover the gate matrix,
whengating (including terminal focus), and that unshiftedmod+pstill opens the file picker.Reviewed by Cursor Bugbot for commit bfd8302. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add
git.createPullRequestandthread.archivekeybindingsmod+shift+pto trigger the create PR action from the active thread, gated by a newgitCanCreatePrcontext key that requires a clean, synced branch with upstream and no open PR.mod+shift+ato archive the active thread; shows an error toast on failure. Both shortcuts are suppressed when terminal focus is active.canCreatePrFromPushedWorkin GitActionsControl.logic.ts to computegitCanCreatePrand wires the keydown handler into GitActionsControl.tsx.gitCanCreatePrcontext key in keybindings.md.Macroscope summarized bfd8302.