mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-09 09:22:48 +03:00
Enforce single-item selection in various actions
We want to show an error when the user tries to invoke an action that expects only a single item to be selected. We're using the GetDisabledReason field to enforce this (as well as DisabledReason on menu items). I've created a ListControllerTrait to store some shared convenience functions for this.
This commit is contained in:
@@ -114,10 +114,18 @@ func (self *ListCursor) CancelRangeSelect() {
|
||||
self.rangeSelectMode = RangeSelectModeNone
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return self.rangeSelectMode != RangeSelectModeNone
|
||||
}
|
||||
|
||||
// Returns true if we are in range select mode and selecting multiple items
|
||||
func (self *ListCursor) AreMultipleItemsSelected() bool {
|
||||
startIdx, endIdx := self.GetSelectionRange()
|
||||
return startIdx != endIdx
|
||||
}
|
||||
|
||||
func (self *ListCursor) GetSelectionRange() (int, int) {
|
||||
if self.IsSelectingRange() {
|
||||
return utils.MinMax(self.selectedIdx, self.rangeStartIdx)
|
||||
|
Reference in New Issue
Block a user