mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-05 00:59:19 +02:00
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).
This commit is contained in:
@ -133,10 +133,19 @@ func (self *ListCursor) GetRangeStartIdx() (int, bool) {
|
|||||||
return 0, false
|
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() {
|
func (self *ListCursor) CancelRangeSelect() {
|
||||||
self.rangeSelectMode = RangeSelectModeNone
|
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
|
// 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.
|
// mode and still only selecting a single item. See AreMultipleItemsSelected below.
|
||||||
func (self *ListCursor) IsSelectingRange() bool {
|
func (self *ListCursor) IsSelectingRange() bool {
|
||||||
|
@ -47,8 +47,8 @@ func (self *BranchesHelper) ConfirmLocalDelete(branches []*models.Branch) error
|
|||||||
if err := self.c.Git().Branch.LocalDelete(branchNames, true); err != nil {
|
if err := self.c.Git().Branch.LocalDelete(branchNames, true); err != nil {
|
||||||
return err
|
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}})
|
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}})
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@ -180,9 +180,7 @@ func (self *BranchesHelper) ConfirmLocalAndRemoteDelete(branches []*models.Branc
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
selectionStart, _ := self.c.Contexts().Branches.GetSelectionRange()
|
self.c.Contexts().Branches.CollapseRangeSelectionToTop()
|
||||||
self.c.Contexts().Branches.SetSelectedLineIdx(selectionStart)
|
|
||||||
|
|
||||||
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
|
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user