From 94ccf46b2a6600e9bb9dd8dbb99b74ab78b64a14 Mon Sep 17 00:00:00 2001 From: majiayu000 <1835304752@qq.com> Date: Tue, 30 Dec 2025 14:36:44 +0800 Subject: [PATCH 1/2] Fix: Preserve screen mode when navigating in and out of submodules When entering a submodule, the current screen mode is now preserved instead of being reset to the default. This makes navigation between parent repos and submodules less jarring, as the user's screen mode preference is maintained. The fix captures the current screen mode before switching to the submodule and passes it to the new repo initialization, while worktrees and regular repo switches continue to use the default behavior. Fixes #5127 Signed-off-by: majiayu000 <1835304752@qq.com> --- pkg/gui/controllers/helpers/repos_helper.go | 26 ++++++++++++++++--- .../controllers/helpers/worktree_helper.go | 4 +-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pkg/gui/controllers/helpers/repos_helper.go b/pkg/gui/controllers/helpers/repos_helper.go index 158606b0100..c82c947220b 100644 --- a/pkg/gui/controllers/helpers/repos_helper.go +++ b/pkg/gui/controllers/helpers/repos_helper.go @@ -49,7 +49,9 @@ func (self *ReposHelper) EnterSubmodule(submodule *models.SubmoduleConfig) error } self.c.State().GetRepoPathStack().Push(wd) - return self.DispatchSwitchToRepo(submodule.FullPath(), context.NO_CONTEXT) + // Preserve the current screen mode when entering submodule + currentScreenMode := self.c.State().GetRepoState().GetScreenMode() + return self.DispatchSwitchToRepoWithScreenMode(submodule.FullPath(), context.NO_CONTEXT, currentScreenMode) } func (self *ReposHelper) getCurrentBranch(path string) string { @@ -141,10 +143,15 @@ func (self *ReposHelper) CreateRecentReposMenu() error { } func (self *ReposHelper) DispatchSwitchToRepo(path string, contextKey types.ContextKey) error { - return self.DispatchSwitchTo(path, self.c.Tr.ErrRepositoryMovedOrDeleted, contextKey) + return self.DispatchSwitchTo(path, self.c.Tr.ErrRepositoryMovedOrDeleted, contextKey, "") } -func (self *ReposHelper) DispatchSwitchTo(path string, errMsg string, contextKey types.ContextKey) error { +func (self *ReposHelper) DispatchSwitchToRepoWithScreenMode(path string, contextKey types.ContextKey, screenMode types.ScreenMode) error { + screenModeStr := screenModeToString(screenMode) + return self.DispatchSwitchTo(path, self.c.Tr.ErrRepositoryMovedOrDeleted, contextKey, screenModeStr) +} + +func (self *ReposHelper) DispatchSwitchTo(path string, errMsg string, contextKey types.ContextKey, screenMode string) error { return self.c.WithWaitingStatus(self.c.Tr.Switching, func(gocui.Task) error { env.UnsetGitLocationEnvVars() originalPath, err := os.Getwd() @@ -177,6 +184,17 @@ func (self *ReposHelper) DispatchSwitchTo(path string, errMsg string, contextKey self.c.Mutexes().RefreshingFilesMutex.Lock() defer self.c.Mutexes().RefreshingFilesMutex.Unlock() - return self.onNewRepo(appTypes.StartArgs{}, contextKey) + return self.onNewRepo(appTypes.StartArgs{ScreenMode: screenMode}, contextKey) }) } + +func screenModeToString(screenMode types.ScreenMode) string { + switch screenMode { + case types.SCREEN_HALF: + return "half" + case types.SCREEN_FULL: + return "full" + default: + return "normal" + } +} diff --git a/pkg/gui/controllers/helpers/worktree_helper.go b/pkg/gui/controllers/helpers/worktree_helper.go index 671743fe626..7f5ac7bff46 100644 --- a/pkg/gui/controllers/helpers/worktree_helper.go +++ b/pkg/gui/controllers/helpers/worktree_helper.go @@ -107,7 +107,7 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo return err } - return self.reposHelper.DispatchSwitchTo(opts.Path, self.c.Tr.ErrWorktreeMovedOrRemoved, contextKey) + return self.reposHelper.DispatchSwitchTo(opts.Path, self.c.Tr.ErrWorktreeMovedOrRemoved, contextKey, "") }) } @@ -161,7 +161,7 @@ func (self *WorktreeHelper) Switch(worktree *models.Worktree, contextKey types.C self.c.LogAction(self.c.Tr.SwitchToWorktree) - return self.reposHelper.DispatchSwitchTo(worktree.Path, self.c.Tr.ErrWorktreeMovedOrRemoved, contextKey) + return self.reposHelper.DispatchSwitchTo(worktree.Path, self.c.Tr.ErrWorktreeMovedOrRemoved, contextKey, "") } func (self *WorktreeHelper) Remove(worktree *models.Worktree, force bool) error { From 1d36d7d8da50c701c3e4914c36dca7ce1ceb9503 Mon Sep 17 00:00:00 2001 From: majiayu000 <1835304752@qq.com> Date: Tue, 30 Dec 2025 14:40:07 +0800 Subject: [PATCH 2/2] fix: Preserve screen mode when navigating in and out of submodules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fix ensures that the current screen mode (normal, half, or full) is preserved when entering and exiting submodules. Previously, the screen mode would reset to normal when navigating into or out of a submodule, which was jarring for users who frequently switch between a submodule and its parent repo. Changes: - Modified EnterSubmodule to capture and pass the current screen mode - Added DispatchSwitchToRepoWithScreenMode method to handle screen mode preservation - Updated Escape action to preserve screen mode when exiting submodules - Added screenModeToString helper to convert screen mode enum to string Fixes #5127 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 Signed-off-by: majiayu000 <1835304752@qq.com> --- pkg/gui/controllers/quit_actions.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/gui/controllers/quit_actions.go b/pkg/gui/controllers/quit_actions.go index 4713a6e23b6..727d01c520d 100644 --- a/pkg/gui/controllers/quit_actions.go +++ b/pkg/gui/controllers/quit_actions.go @@ -83,7 +83,9 @@ func (self *QuitActions) Escape() error { repoPathStack := self.c.State().GetRepoPathStack() if !repoPathStack.IsEmpty() { - return self.c.Helpers().Repos.DispatchSwitchToRepo(repoPathStack.Pop(), context.NO_CONTEXT) + // Preserve the current screen mode when exiting submodule + currentScreenMode := self.c.State().GetRepoState().GetScreenMode() + return self.c.Helpers().Repos.DispatchSwitchToRepoWithScreenMode(repoPathStack.Pop(), context.NO_CONTEXT, currentScreenMode) } if self.c.UserConfig().QuitOnTopLevelReturn {