From 6203a4e41119d04c738a5f2aa8fca7e2de71904d Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 2 Jul 2026 22:07:16 +0200 Subject: [PATCH] Move post-COMMIT_FILES-refresh work into Then SwitchToDiffFilesController.enter calls SelectPath and Context.Push right after a (SYNC, by default) COMMIT_FILES refresh. This works today because the model write currently happens synchronously in the worker before Refresh's wg.Wait() returns, but an upcoming commit will bounce that write onto the UI thread instead, at which point wg.Wait() no longer guarantees it's been applied, and SelectPath would operate on a stale tree. Move both calls into Then ahead of that change, for the same reason as the earlier FILES-scope commit: Then is already queued via OnUIThread, so this is behavior-preserving on its own. Co-Authored-By: Claude Sonnet 5 --- .../switch_to_diff_files_controller.go | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go index c2ff4d674..afdf92c80 100644 --- a/pkg/gui/controllers/switch_to_diff_files_controller.go +++ b/pkg/gui/controllers/switch_to_diff_files_controller.go @@ -90,18 +90,19 @@ func (self *SwitchToDiffFilesController) enter() error { self.c.Refresh(types.RefreshOptions{ Scope: []types.RefreshableView{types.COMMIT_FILES}, + Then: func() error { + if filterPath := self.c.Modes().Filtering.GetPath(); filterPath != "" { + path, err := filepath.Rel(self.c.Git().RepoPaths.RepoPath(), filterPath) + if err != nil { + path = filterPath + } + commitFilesContext.CommitFileTreeViewModel.SelectPath( + filepath.ToSlash(path), self.c.UserConfig().Gui.ShowRootItemInFileTree) + } + self.c.Context().Push(commitFilesContext, types.OnFocusOpts{}) + return nil + }, }) - - if filterPath := self.c.Modes().Filtering.GetPath(); filterPath != "" { - path, err := filepath.Rel(self.c.Git().RepoPaths.RepoPath(), filterPath) - if err != nil { - path = filterPath - } - commitFilesContext.CommitFileTreeViewModel.SelectPath( - filepath.ToSlash(path), self.c.UserConfig().Gui.ShowRootItemInFileTree) - } - - self.c.Context().Push(commitFilesContext, types.OnFocusOpts{}) return nil }