diff --git a/pkg/gui/controllers/helpers/branches_helper.go b/pkg/gui/controllers/helpers/branches_helper.go index 3006ba638..5f26c8099 100644 --- a/pkg/gui/controllers/helpers/branches_helper.go +++ b/pkg/gui/controllers/helpers/branches_helper.go @@ -504,18 +504,7 @@ func (self *BranchesHelper) PrepareFastForward(branches []*models.Branch) (func( // Runs f on a worker with all the given branches shown as being in the given // operation while it runs func (self *BranchesHelper) WithInlineStatusOnBranches(branches []*models.Branch, operation types.ItemOperation, f func(gocui.Task) error) error { - return self.c.WithInlineStatus(branches[0], operation, context.LOCAL_BRANCHES_CONTEXT_KEY, func(task gocui.Task) error { - for _, branch := range branches[1:] { - self.c.State().SetItemOperation(branch, operation) - } - defer func() { - for _, branch := range branches[1:] { - self.c.State().ClearItemOperation(branch) - } - }() - - return f(task) - }) + return WithInlineStatusOnItems(self.c, branches, operation, context.LOCAL_BRANCHES_CONTEXT_KEY, f) } func (self *BranchesHelper) fetchUpstreamBranches(task gocui.Task, branches []*models.Branch) error { diff --git a/pkg/gui/controllers/helpers/inline_status_helper.go b/pkg/gui/controllers/helpers/inline_status_helper.go index 814a11406..48c545bc7 100644 --- a/pkg/gui/controllers/helpers/inline_status_helper.go +++ b/pkg/gui/controllers/helpers/inline_status_helper.go @@ -94,6 +94,23 @@ func (self *InlineStatusHelper) WithInlineStatus(opts InlineStatusOpts, f func(g } } +// Runs f on a worker with all the given items shown as being in the given +// operation while it runs +func WithInlineStatusOnItems[T types.HasUrn](c *HelperCommon, items []T, operation types.ItemOperation, contextKey types.ContextKey, f func(gocui.Task) error) error { + return c.WithInlineStatus(items[0], operation, contextKey, func(task gocui.Task) error { + for _, item := range items[1:] { + c.State().SetItemOperation(item, operation) + } + defer func() { + for _, item := range items[1:] { + c.State().ClearItemOperation(item) + } + }() + + return f(task) + }) +} + func (self *InlineStatusHelper) start(opts InlineStatusOpts) { self.c.State().SetItemOperation(opts.Item, opts.Operation)