From fc6ed0774747e237c281a307047e14810c101e87 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 26 Sep 2026 18:41:08 +0200 Subject: [PATCH] Generalize showing an inline status on several branches to any items Deleting and pushing a range selection of tags will need to show their operation on all the selected tags. Move the code from BranchesHelper into a generic function that takes the items and the key of the context that shows them. Co-Authored-By: Claude Opus 5.5 (1M context) --- pkg/gui/controllers/helpers/branches_helper.go | 13 +------------ .../controllers/helpers/inline_status_helper.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 12 deletions(-) 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)