Skip to content

git_ui: Fix branch picker stealing vim keys in Git panel#52687

Merged
ChristopherBiscardi merged 1 commit intozed-industries:mainfrom
saberoueslati:fix-branch-picker-vim-focus
Mar 31, 2026
Merged

git_ui: Fix branch picker stealing vim keys in Git panel#52687
ChristopherBiscardi merged 1 commit intozed-industries:mainfrom
saberoueslati:fix-branch-picker-vim-focus

Conversation

@saberoueslati
Copy link
Copy Markdown
Contributor

@saberoueslati saberoueslati commented Mar 29, 2026

Context

When vim_mode is enabled, opening the branch selector popover in the Git panel and pressing i, j, k, or x triggered Git panel actions (FocusEditor, SelectNext, ToggleStaged, etc.) instead of reaching the picker's search field.

The "GitPanel && ChangesList" keybinding block in vim.json matched whenever any child of the git panel's focus handle was focused — including the branch picker popover — because GitPanel::dispatch_context() adds ChangesList based on focus_handle.contains_focused(), which is true for all children, not just the changes list itself.

The branch picker's root element already sets .key_context("GitBranchSelector") (branch_picker.rs). GPUI's Not predicate evaluates against the entire context path, so adding && !GitBranchSelector to the block's context suppresses all those bindings whenever the picker is open, and restores them exactly as before once it's closed.

Closes #52617

Video of the manual test of the fix below :

Screencast.from.2026-03-29.22-01-11.webm

How to Review

  • assets/keymaps/vim.json : changed the "GitPanel && ChangesList" context string ,I added&& !GitBranchSelector.

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 branch picker in the Git panel stealing vim keystrokes (i, j, k, x) when vim mode is enabled

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 29, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator bot requested review from a team, nathansobo and osiewicz and removed request for a team March 29, 2026 21:04
@zed-community-bot zed-community-bot bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Mar 29, 2026
@ChristopherBiscardi
Copy link
Copy Markdown
Contributor

thanks! I've validated that this works as intended, and it seems well-scoped to the issue

@ChristopherBiscardi ChristopherBiscardi merged commit 7315aad into zed-industries:main Mar 31, 2026
43 checks passed
ChristopherBiscardi pushed a commit that referenced this pull request Mar 31, 2026
## Context

Fixes a regression where typing a space in the Git Panel's "Switch
Branch" picker would make no response at all instead of inserting the
character. The same picker in the title-bar Git Switcher was unaffected.

Root cause: `PopoverMenu` links the opened menu's focus handle into the
parent element's dispatch tree so that `contains_focused` returns `true`
on the parent while the popover is open. `GitPanel::dispatch_context`
uses
`contains_focused` to decide whether to add the `ChangesList` key
context, so that context is active while the branch picker is open.
Because `Picker` and `Editor` have no binding for a bare `space`,
dispatch fell through to
the `"GitPanel && ChangesList"` binding, which maps `space` to
`git::ToggleStaged`, consuming the keystroke before it could reach the
text input.

The fix narrows the context guard to `"GitPanel && ChangesList &&
!GitBranchSelector"`,
so those bindings are skipped whenever the branch picker (or any other
`GitBranchSelector` context) is focused inside the panel.

The same change is applied to the vim keymap, which would have similarly
intercepted `k`,
`j`, `x`, and other letter keys typed in the picker, this behavior was
observed in #52617 and I
made the same fix in #52687

Closes #52771 and potentially
#52617

Video of the manual test of the fix below :

[Screencast from 2026-03-31
00-01-54.webm](https://github.com/user-attachments/assets/76f64507-4f5a-4a8e-8582-4cdb9bec584c)

## How to Review

- `assets/keymaps/default-linux.json`, `default-windows.json`,
`default-macos.json`, `vim.json` : identical one-line change in each: I
added `&& !GitBranchSelector` to
  the `"GitPanel && ChangesList"` 
. No Rust changes needed.

## 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 space and other keys being swallowed when typing in the Git
Panel branch picker
@zed-zippy zed-zippy bot added the PR state:needs review Used to label PRs that are in need of a post-merge approval label Apr 6, 2026
@ChristopherBiscardi
Copy link
Copy Markdown
Contributor

@zed-zippy approve

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 first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Branch picker loses focus with vim mode

4 participants