Skip to content

Commit 3e11e34

Browse files
committed
Fix race condition with reselecting the focused branch and rendering
In ff4ae4a 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 ff4ae4a was trying to fix.
1 parent daf1fd3 commit 3e11e34

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: pkg/gui/controllers/helpers/refresh_helper.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -490,16 +490,18 @@ func (self *RefreshHelper) refreshBranches(refreshWorktrees bool, keepBranchSele
490490
self.refreshView(self.c.Contexts().Worktrees)
491491
}
492492

493-
self.refreshView(self.c.Contexts().Branches)
494-
495493
if !keepBranchSelectionIndex && prevSelectedBranch != nil {
494+
self.searchHelper.ReApplyFilter(self.c.Contexts().Branches)
495+
496496
_, idx, found := lo.FindIndexOf(self.c.Contexts().Branches.GetItems(),
497497
func(b *models.Branch) bool { return b.Name == prevSelectedBranch.Name })
498498
if found {
499499
self.c.Contexts().Branches.SetSelectedLineIdx(idx)
500500
}
501501
}
502502

503+
self.refreshView(self.c.Contexts().Branches)
504+
503505
// Need to re-render the commits view because the visualization of local
504506
// branch heads might have changed
505507
self.c.Mutexes().LocalCommitsMutex.Lock()

0 commit comments

Comments
 (0)