From 3e11e34181c8b26ae1048a57b47148c51e495d04 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 15 Feb 2025 09:49:55 +0100 Subject: [PATCH] Fix race condition with reselecting the focused branch and rendering In ff4ae4a544 we changed the order of the calls to render before selecting the branch. This was done only to save an extra call to ReApplyFilter, which is done by refreshView; I claimed that the order of refreshView vs. SetSelectedLineIdx doesn't matter here. I guess I was wrong about that, it makes the integration test custom_commands/suggestions_preset.go flaky. To fix this, put the refreshView call back to where it was (after the SetSelectedLineIdx call), and instead insert an extra call to ReApplyFilter where necessary to fix the bug that ff4ae4a544 was trying to fix. --- pkg/gui/controllers/helpers/refresh_helper.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index a5be655a1..cac9310d1 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -490,9 +490,9 @@ func (self *RefreshHelper) refreshBranches(refreshWorktrees bool, keepBranchSele self.refreshView(self.c.Contexts().Worktrees) } - self.refreshView(self.c.Contexts().Branches) - if !keepBranchSelectionIndex && prevSelectedBranch != nil { + self.searchHelper.ReApplyFilter(self.c.Contexts().Branches) + _, idx, found := lo.FindIndexOf(self.c.Contexts().Branches.GetItems(), func(b *models.Branch) bool { return b.Name == prevSelectedBranch.Name }) if found { @@ -500,6 +500,8 @@ func (self *RefreshHelper) refreshBranches(refreshWorktrees bool, keepBranchSele } } + self.refreshView(self.c.Contexts().Branches) + // Need to re-render the commits view because the visualization of local // branch heads might have changed self.c.Mutexes().LocalCommitsMutex.Lock()