git_ui: Fix Enter key selecting branch in commit modal branch picker#58366
Conversation
ChristopherBiscardi
left a comment
There was a problem hiding this comment.
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!
|
@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. |
…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
Context
When the "Switch branch" picker is opened from the git commit modal and the user presses Enter, a
\ncharacter was inserted into the input instead of confirming the branch selection.The
"GitCommit > Editor"keymap context boundentertoeditor::Newline. This context matches anyEditordescended fromGitCommitin the element tree, including the single-line search editor inside the branch picker popover. Because a context-path binding is more specific than the globalenter: menu::Confirmbinding, it took precedence and the picker never received the confirm action.The commit message editor uses
EditorMode::AutoHeight(reported in key context asmode == auto_height); the picker's search editor usesEditorMode::SingleLine. Narrowing the context to"GitCommit > Editor && mode == auto_height"restricts theeditor::Newlinebinding to the commit message editor only. Single-line editors inside the same modal now fall through to the globalenter: 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
Release Notes: