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 Fix git panel context menu keybinding jitter 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
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.

Git panel shortcut key jitter

2 participants