Skip to content

git_ui: Fix Enter key selecting branch in commit modal branch picker#58366

Merged
ChristopherBiscardi merged 1 commit into
zed-industries:mainfrom
saberoueslati:fix/commit-modal-branch-picker-enter-key
Jun 3, 2026
Merged

git_ui: Fix Enter key selecting branch in commit modal branch picker#58366
ChristopherBiscardi merged 1 commit into
zed-industries:mainfrom
saberoueslati:fix/commit-modal-branch-picker-enter-key

Conversation

@saberoueslati
Copy link
Copy Markdown
Contributor

@saberoueslati saberoueslati commented Jun 2, 2026

Context

When the "Switch branch" picker is opened from the git commit modal and the user presses Enter, a \n character was inserted into the input instead of confirming the branch selection.

The "GitCommit > Editor" keymap context bound enter to editor::Newline. This context matches any Editor descended from GitCommit in the element tree, including the single-line search editor inside the branch picker popover. Because a context-path binding is more specific than the global enter: menu::Confirm binding, it took precedence and the picker never received the confirm action.

The commit message editor uses EditorMode::AutoHeight (reported in key context as mode == auto_height); the picker's search editor uses EditorMode::SingleLine. Narrowing the context to "GitCommit > Editor && mode == auto_height" restricts the editor::Newline binding to the commit message editor only. Single-line editors inside the same modal now fall through to the global enter: menu::Confirm, which correctly confirms the selection.

Closes #58022

How to Review

Three identical one-line changes, one per platform keymap (default-linux.json, default-macos.json, default-windows.json):

  • "GitCommit > Editor""GitCommit > Editor && mode == auto_height"

Video of manual test after fix :

Screencast.from.2026-06-02.23-16-32.webm

Self-Review Checklist

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Fixed Enter key inserting a newline instead of selecting a branch in the commit modal branch picker

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jun 2, 2026
@ChristopherBiscardi ChristopherBiscardi self-assigned this Jun 3, 2026
Copy link
Copy Markdown
Contributor

@ChristopherBiscardi ChristopherBiscardi left a comment

Choose a reason for hiding this comment

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

the mode as a selector feels a bit awkward, but what's more awkward is that we even let users change the branch during a git commit, which is a weird operation in my opinion. I can't think of a good reason to change a branch while mid-commit message, but that's not this PR's problem.

This PR does fix the issue, thanks!

Image

@ChristopherBiscardi ChristopherBiscardi added this pull request to the merge queue Jun 3, 2026
Merged via the queue into zed-industries:main with commit 5791ebc Jun 3, 2026
36 checks passed
@saberoueslati
Copy link
Copy Markdown
Contributor Author

saberoueslati commented Jun 3, 2026

@ChristopherBiscardi Here is my 2 cents on what you spoke of.

I agree on most of what you said but one caveat, I change branches right before a commit for just one use case, when I'm working on an issue I usually work on branch main or master then right before a first commit I create a branch for the change and commit there, maybe what would make more sense there is a button that would let you just create a new branch that you switch to then you write your commit message and commit, a button that might be similar in shape and functionality to what appears in the screenshot you put in your comment.

dandv pushed a commit to dandv/zed that referenced this pull request Jun 3, 2026
…ed-industries#58366)

## Context

When the "Switch branch" picker is opened from the git commit modal and
the user presses Enter, a `\n` character was inserted into the input
instead of confirming the branch selection.

The `"GitCommit > Editor"` keymap context bound `enter` to
`editor::Newline`. This context matches *any* `Editor` descended from
`GitCommit` in the element tree, including the single-line search editor
inside the branch picker popover. Because a context-path binding is more
specific than the global `enter: menu::Confirm` binding, it took
precedence and the picker never received the confirm action.

The commit message editor uses `EditorMode::AutoHeight` (reported in key
context as `mode == auto_height`); the picker's search editor uses
`EditorMode::SingleLine`. Narrowing the context to `"GitCommit > Editor
&& mode == auto_height"` restricts the `editor::Newline` binding to the
commit message editor only. Single-line editors inside the same modal
now fall through to the global `enter: menu::Confirm`, which correctly
confirms the selection.

Closes zed-industries#58022

## How to Review

Three identical one-line changes, one per platform keymap
(`default-linux.json`, `default-macos.json`, `default-windows.json`):

- `"GitCommit > Editor"` → `"GitCommit > Editor && mode == auto_height"`

Video of manual test after fix :

[Screencast from 2026-06-02
23-16-32.webm](https://github.com/user-attachments/assets/67652cc5-4f8d-42f4-a5a9-ade3499ee880)

## Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the UI/UX checklist
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed Enter key inserting a newline instead of selecting a branch in
the commit modal branch picker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Branch cannot be selected by Enter key in the commit dialog

2 participants