Skip to content

Prevent multibuffer items from switching active repository - #58795

Open
mengh04 wants to merge 4 commits into
zed-industries:mainfrom
mengh04:fix-multirepo-git-panel-glitch
Open

Prevent multibuffer items from switching active repository#58795
mengh04 wants to merge 4 commits into
zed-industries:mainfrom
mengh04:fix-multirepo-git-panel-glitch

Conversation

@mengh04

@mengh04 mengh04 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Fixes the git panel's active repository being silently overridden by the cursor position in ProjectDiff.

Summary

When a multi-buffer item (e.g. ProjectDiff) gains focus, the workspace calls set_active_repo_for_path with the cursor's project path to automatically switch the active git repository. This was safe when multi-buffer items returned None from active_project_path, but PR #57236 changed ProjectDiff to return the cursor-based path (for project panel highlighting), inadvertently allowing the cursor position to override the user's explicit repository selection.

Fix the issue by restoring the Singleton guard that was removed in PR #57236: only call set_active_repo_for_path when the active item is backed by a single buffer.

Additionally, subscribe ProjectDiff to ActiveRepositoryChanged events so that its branch_diff updates when the user switches repos via the repository selector.

Changes

  • workspace.rs: Only call set_active_repo_for_path when the active item's buffer_kind is Singleton. Multi-buffer items (e.g. ProjectDiff, diagnostics, search results) span multiple repositories, so their cursor position should not trigger an automatic repository switch.
  • project_diff.rs: Subscribe to GitStoreEvent::ActiveRepositoryChanged to keep branch_diff in sync when the active repository is changed via the repository selector.

Before

before.mp4

After

after.mp4

Closes #58792

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 git panel repository being silently overridden when clicking files in a multi-repository workspace.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jun 7, 2026
@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 Jun 7, 2026
@mengh04
mengh04 force-pushed the fix-multirepo-git-panel-glitch branch from cf47900 to 8de933d Compare June 7, 2026 23:08
@maxdeviant maxdeviant changed the title fix(git): prevent multi-buffer items from switching active repository Prevent multibuffer items from switching active repository Jun 7, 2026
@ChristopherBiscardi ChristopherBiscardi added the area:integrations/git Git integration feedback label Jun 9, 2026
@mengh04
mengh04 force-pushed the fix-multirepo-git-panel-glitch branch from 8de933d to 3da1662 Compare June 9, 2026 09:32
When a multi-buffer item (e.g. ProjectDiff) gains focus, the workspace
calls  with the cursor's project path to
automatically switch the active git repository.  This was safe when
multi-buffer items returned  from , but
PR zed-industries#57236 changed ProjectDiff to return the cursor-based path (for
project panel highlighting), inadvertently allowing the cursor position
to override the user's explicit repository selection.

Fix the issue by restoring the Singleton guard that was removed in
PR zed-industries#57236: only call  when the active item
is backed by a single buffer.

Additionally, subscribe ProjectDiff to  events
so that its branch_diff updates when the user switches repos via the
repository selector.

Fixes zed-industries#58792
@mengh04
mengh04 force-pushed the fix-multirepo-git-panel-glitch branch from 3da1662 to 5814639 Compare July 11, 2026 20:05
@mengh04
mengh04 force-pushed the fix-multirepo-git-panel-glitch branch from e2daf3a to 81393c7 Compare August 1, 2026 17:01
@mengh04

mengh04 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

I've just added a regression test covering this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:integrations/git Git integration feedback 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

Status: No status

Development

Successfully merging this pull request may close these issues.

Zed randomly switches projects when cycling through multibuffers

2 participants