From 4b33efffbe53c6a58b75c88d336674feac95b72c Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 4 Jul 2025 17:04:00 +0200 Subject: [PATCH] Collapse selection after deleting a range of remote branches We only want to do this when the function is called from the remote branches panel. It can also be called with a selection of local branches in order to delete their remote branches, but in this case the selection shouldn't be collapsed because the local branches stay around. --- pkg/gui/controllers/branches_controller.go | 2 +- pkg/gui/controllers/helpers/branches_helper.go | 5 ++++- pkg/gui/controllers/remote_branches_controller.go | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 47520a653..77e22f1c3 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -535,7 +535,7 @@ func (self *BranchesController) remoteDelete(branches []*models.Branch) error { remoteBranches := lo.Map(branches, func(branch *models.Branch, _ int) *models.RemoteBranch { return &models.RemoteBranch{Name: branch.UpstreamBranch, RemoteName: branch.UpstreamRemote} }) - return self.c.Helpers().BranchesHelper.ConfirmDeleteRemote(remoteBranches) + return self.c.Helpers().BranchesHelper.ConfirmDeleteRemote(remoteBranches, false) } func (self *BranchesController) localAndRemoteDelete(branches []*models.Branch) error { diff --git a/pkg/gui/controllers/helpers/branches_helper.go b/pkg/gui/controllers/helpers/branches_helper.go index 4bb390b3e..8760c4366 100644 --- a/pkg/gui/controllers/helpers/branches_helper.go +++ b/pkg/gui/controllers/helpers/branches_helper.go @@ -82,7 +82,7 @@ func (self *BranchesHelper) ConfirmLocalDelete(branches []*models.Branch) error return nil } -func (self *BranchesHelper) ConfirmDeleteRemote(remoteBranches []*models.RemoteBranch) error { +func (self *BranchesHelper) ConfirmDeleteRemote(remoteBranches []*models.RemoteBranch, resetRemoteBranchesSelection bool) error { var title string if len(remoteBranches) == 1 { title = utils.ResolvePlaceholderString( @@ -115,6 +115,9 @@ func (self *BranchesHelper) ConfirmDeleteRemote(remoteBranches []*models.RemoteB return err } self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}}) + if resetRemoteBranchesSelection { + self.c.Contexts().RemoteBranches.CollapseRangeSelectionToTop() + } return nil }) }, diff --git a/pkg/gui/controllers/remote_branches_controller.go b/pkg/gui/controllers/remote_branches_controller.go index 304baa125..629bbbaa3 100644 --- a/pkg/gui/controllers/remote_branches_controller.go +++ b/pkg/gui/controllers/remote_branches_controller.go @@ -133,7 +133,7 @@ func (self *RemoteBranchesController) context() *context.RemoteBranchesContext { } func (self *RemoteBranchesController) delete(selectedBranches []*models.RemoteBranch) error { - return self.c.Helpers().BranchesHelper.ConfirmDeleteRemote(selectedBranches) + return self.c.Helpers().BranchesHelper.ConfirmDeleteRemote(selectedBranches, true) } func (self *RemoteBranchesController) merge(selectedBranch *models.RemoteBranch) error {