Skip to content

Commit 80a614d

Browse files
committed
Fix collapsing the range selection after deleting branches
We had code already that was supposed to do this, but it didn't work. It should have used SetSelection() instead of SetSelectedLineIdx(); the latter doesn't actually cancel a range selection. Introduce a new function specifically for collapsing the range after deleting multiple items, so that clients don't need two calls (we'll add a bunch more in this branch).
1 parent 61ff8a4 commit 80a614d

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

pkg/gui/context/traits/list_cursor.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,19 @@ func (self *ListCursor) GetRangeStartIdx() (int, bool) {
133133
return 0, false
134134
}
135135

136+
// Cancel range select mode, but keep the "moving end" of the range selected.
137+
// Used when pressing 'v' or escape to toggle range select mode, for example.
136138
func (self *ListCursor) CancelRangeSelect() {
137139
self.rangeSelectMode = RangeSelectModeNone
138140
}
139141

142+
// Cancel range select mode, but keep the top of the range selected. Note that
143+
// this is different from CancelRangeSelect. Useful after deleting a range of items.
144+
func (self *ListCursor) CollapseRangeSelectionToTop() {
145+
start, _ := self.GetSelectionRange()
146+
self.SetSelection(start)
147+
}
148+
140149
// Returns true if we are in range select mode. Note that we may be in range select
141150
// mode and still only selecting a single item. See AreMultipleItemsSelected below.
142151
func (self *ListCursor) IsSelectingRange() bool {

pkg/gui/controllers/helpers/branches_helper.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ func (self *BranchesHelper) ConfirmLocalDelete(branches []*models.Branch) error
4747
if err := self.c.Git().Branch.LocalDelete(branchNames, true); err != nil {
4848
return err
4949
}
50-
selectionStart, _ := self.c.Contexts().Branches.GetSelectionRange()
51-
self.c.Contexts().Branches.SetSelectedLineIdx(selectionStart)
50+
51+
self.c.Contexts().Branches.CollapseRangeSelectionToTop()
5252
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}})
5353
return nil
5454
})
@@ -180,9 +180,7 @@ func (self *BranchesHelper) ConfirmLocalAndRemoteDelete(branches []*models.Branc
180180
return err
181181
}
182182

183-
selectionStart, _ := self.c.Contexts().Branches.GetSelectionRange()
184-
self.c.Contexts().Branches.SetSelectedLineIdx(selectionStart)
185-
183+
self.c.Contexts().Branches.CollapseRangeSelectionToTop()
186184
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
187185
return nil
188186
})

0 commit comments

Comments
 (0)