fix: git plugin tracks selected workspace on tab switch#144
Open
fix: git plugin tracks selected workspace on tab switch#144
Conversation
When navigating away from the workspace plugin, check if the selected worktree differs from the current WorkDir and trigger a context switch. This ensures the git plugin (and all other plugins) reinitialize with the correct worktree when the user switches tabs. Changes: - Add WorkspaceContextProvider interface to plugin package - Implement SelectedWorkDir() on workspace plugin - Check workspace context in SetActivePlugin and trigger worktree switch - Return path for main worktree too (fixes switch-back-to-main bug) Fixes #143
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #143 — Git plugin doesn't track selected workspace.
When navigating away from the workspace plugin to another tab (e.g., git), the app now checks if the workspace plugin has a different worktree selected and triggers a full context switch. This ensures the git plugin (branch, status, diff, commits) reflects the worktree the user was just looking at.
Changes
internal/plugin/plugin.go: AddedWorkspaceContextProviderinterface — optional capability for plugins that manage workspace/worktree selectioninternal/plugins/workspace/plugin.go: ImplementedSelectedWorkDir()on workspace plugin, returning the selected worktree path (including main worktree, fixing switch-back-to-main)internal/app/model.go:SetActivePlugin()now checks if the leaving plugin implementsWorkspaceContextProviderand triggersswitchWorktree()when the selected workspace differs from currentWorkDirinternal/plugins/workspace/selected_workdir_test.go: Unit tests forSelectedWorkDir()How it works
feature-xSetActivePlugindetects workspace plugin implementsWorkspaceContextProviderSelectedWorkDir()→ returns/path/to/feature-xWorkDir— they differswitchWorktree()→switchProject()→Registry.Reinit()Bug fix detail
The previous (stashed) implementation returned empty string for the main worktree (
IsMaincheck), which meant switching back to main from a feature worktree was silently skipped. Fixed by always returning the path and letting the caller's normalization comparison handle the no-op case.Testing
go test ./...— all pass