Skip to content

Fix git panel context menu keybinding jitter#52217

Merged
Veykril merged 3 commits intozed-industries:mainfrom
Dnreikronos:fix/git-panel-context-menu-keybinding-jitter-51813
Mar 24, 2026
Merged

Fix git panel context menu keybinding jitter#52217
Veykril merged 3 commits intozed-industries:mainfrom
Dnreikronos:fix/git-panel-context-menu-keybinding-jitter-51813

Conversation

@Dnreikronos
Copy link
Copy Markdown
Contributor

Context

The git panel's context menu caused visual jitter (flickering/jumping) when opened via right-click on a tracked file. The root cause was in dispatch_context(): it used self.focus_handle == focused to check if the panel itself was directly focused, but when a context menu opened, focus moved to the menu (a child element), causing the "menu" and "ChangesList" key contexts to be dropped. This triggered a re-render with different keybindings, which re-added them, creating a loop of jitter.

The fix replaces the direct focus equality check with self.focus_handle.contains_focused(window, cx), which returns true when any child element (including the context menu) holds focus within the panel's focus tree. This is consistent with how other panels (project panel, outline panel, collab panel) handle focus-based dispatch contexts.

Closes #51813

Demo

Before fix:

before_fix.mp4

After fix:

after_fix.mp4

How to Review

This is a small, focused change in a single file: crates/git_ui/src/git_panel.rs.

  1. The fix (~line 974): dispatch_context() method — the old code checked direct focus equality (self.focus_handle == focused), the new code uses self.focus_handle.contains_focused(window, cx) and restructures the conditionals so CommitEditor is checked first via if/else if.
  2. The test (~line 7871): test_dispatch_context_with_focus_states — verifies 4 focus state transitions: commit editor focused, changes list focused, back to commit editor, and back to changes list. Each case asserts the correct key contexts are present/absent.

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:

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Mar 23, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator Bot requested review from a team, Veykril and cole-miller and removed request for a team March 23, 2026 14:48
@maxdeviant maxdeviant changed the title Fix/git panel context menu keybinding jitter #51813 Mar 23, 2026
Copy link
Copy Markdown
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

Thanks!

@Veykril Veykril enabled auto-merge (squash) March 24, 2026 07:54
auto-merge was automatically disabled March 24, 2026 11:43

Head branch was pushed to by a user without write access

@Dnreikronos Dnreikronos requested a review from Veykril March 24, 2026 11:43
@Veykril Veykril enabled auto-merge (squash) March 24, 2026 11:44
@Veykril Veykril merged commit 45be23c into zed-industries:main Mar 24, 2026
31 checks passed
piper-of-dawn pushed a commit to piper-of-dawn/zed that referenced this pull request Apr 25, 2026
Context

The git panel's context menu caused visual jitter (flickering/jumping)
when opened via right-click on a tracked file. The root cause was in
`dispatch_context()`: it used `self.focus_handle == focused` to check if
the panel itself was directly focused, but when a context menu opened,
focus moved to the menu (a child element), causing the `"menu"` and
`"ChangesList"` key contexts to be dropped. This triggered a re-render
with different keybindings, which re-added them, creating a loop of
jitter.

The fix replaces the direct focus equality check with
`self.focus_handle.contains_focused(window, cx)`, which returns `true`
when any child element (including the context menu) holds focus within
the panel's focus tree. This is consistent with how other panels
(project panel, outline panel, collab panel) handle focus-based dispatch
contexts.

Closes zed-industries#51813

## Demo

**Before fix:**




https://github.com/user-attachments/assets/e18d49b2-72a6-4411-8ec5-519e36628f29


**After fix:**



https://github.com/user-attachments/assets/94c936d2-1e81-4d28-a86a-8b1ed76ddde1



## How to Review

This is a small, focused change in a single file:
`crates/git_ui/src/git_panel.rs`.

1. **The fix** (~line 974): `dispatch_context()` method — the old code
checked direct focus equality (`self.focus_handle == focused`), the new
code uses `self.focus_handle.contains_focused(window, cx)` and
restructures the conditionals so `CommitEditor` is checked first via
`if/else if`.
2. **The test** (~line 7871): `test_dispatch_context_with_focus_states`
— verifies 4 focus state transitions: commit editor focused, changes
list focused, back to commit editor, and back to changes list. Each case
asserts the correct key contexts are present/absent.

## 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](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed git panel context menu jitter caused by keybinding dispatch
context flickering when right-clicking on tracked files (zed-industries#51813)
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

2 participants