Skip to content

Commit 101bbb0

Browse files
authored
Fix race condition with reselecting the focused branch and rendering (#4268)
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. I still don't think there was any user facing problem caused by this (@ChrisMcD1 correct me if I'm wrong), so I don't think we need to cut a 0.46.1 release with the fix (otherwise it would have been a regression in 0.46), and I only label it as `maintenance` because it only fixes CI. Fixes #4267.
2 parents daf1fd3 + 3e11e34 commit 101bbb0

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)