diff --git a/pkg/gui/context/traits/list_cursor.go b/pkg/gui/context/traits/list_cursor.go index c471d9a0f..3b3e58639 100644 --- a/pkg/gui/context/traits/list_cursor.go +++ b/pkg/gui/context/traits/list_cursor.go @@ -133,10 +133,19 @@ func (self *ListCursor) GetRangeStartIdx() (int, bool) { return 0, false } +// Cancel range select mode, but keep the "moving end" of the range selected. +// Used when pressing 'v' or escape to toggle range select mode, for example. func (self *ListCursor) CancelRangeSelect() { self.rangeSelectMode = RangeSelectModeNone } +// Cancel range select mode, but keep the top of the range selected. Note that +// this is different from CancelRangeSelect. Useful after deleting a range of items. +func (self *ListCursor) CollapseRangeSelectionToTop() { + start, _ := self.GetSelectionRange() + self.SetSelection(start) +} + // Returns true if we are in range select mode. Note that we may be in range select // mode and still only selecting a single item. See AreMultipleItemsSelected below. func (self *ListCursor) IsSelectingRange() bool { diff --git a/pkg/gui/controllers/helpers/branches_helper.go b/pkg/gui/controllers/helpers/branches_helper.go index 2478dee58..4bb390b3e 100644 --- a/pkg/gui/controllers/helpers/branches_helper.go +++ b/pkg/gui/controllers/helpers/branches_helper.go @@ -47,8 +47,8 @@ func (self *BranchesHelper) ConfirmLocalDelete(branches []*models.Branch) error if err := self.c.Git().Branch.LocalDelete(branchNames, true); err != nil { return err } - selectionStart, _ := self.c.Contexts().Branches.GetSelectionRange() - self.c.Contexts().Branches.SetSelectedLineIdx(selectionStart) + + self.c.Contexts().Branches.CollapseRangeSelectionToTop() self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}}) return nil }) @@ -180,9 +180,7 @@ func (self *BranchesHelper) ConfirmLocalAndRemoteDelete(branches []*models.Branc return err } - selectionStart, _ := self.c.Contexts().Branches.GetSelectionRange() - self.c.Contexts().Branches.SetSelectedLineIdx(selectionStart) - + self.c.Contexts().Branches.CollapseRangeSelectionToTop() self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}}) return nil })