diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2024-01-13 17:40:28 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2024-01-19 10:50:49 +1100 |
commit | 280b4d60f893a0e20897091ab02617c32180b45d (patch) | |
tree | 9665a327ae7fe4d468637fc0e10327a223a113ed /pkg/gui/controllers/helpers/cherry_pick_helper.go | |
parent | 54bd94ad24ca24ca12fab59e9dbf0d79fe7681da (diff) |
Support select range for cherry pick
This requires us to change the 'v' keybinding for paste to something else,
now that 'v' is used globally for toggling range select. So I'm using
'shift+v' and I'm likewise changing 'c' to 'shift+c' for copying, so
that they're consistent.
We will need to clearly communicate this change in keybindings.
Diffstat (limited to 'pkg/gui/controllers/helpers/cherry_pick_helper.go')
-rw-r--r-- | pkg/gui/controllers/helpers/cherry_pick_helper.go | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/pkg/gui/controllers/helpers/cherry_pick_helper.go b/pkg/gui/controllers/helpers/cherry_pick_helper.go index 4f455ca30..61a37220b 100644 --- a/pkg/gui/controllers/helpers/cherry_pick_helper.go +++ b/pkg/gui/controllers/helpers/cherry_pick_helper.go @@ -5,6 +5,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking" "github.com/jesseduffield/lazygit/pkg/gui/types" + "github.com/samber/lo" ) type CherryPickHelper struct { @@ -45,25 +46,30 @@ func (self *CherryPickHelper) Copy(commit *models.Commit, commitsList []*models. return self.rerender() } -func (self *CherryPickHelper) CopyRange(selectedIndex int, commitsList []*models.Commit, context types.Context) error { +func (self *CherryPickHelper) CopyRange(commitsList []*models.Commit, context types.IListContext) error { + startIdx, endIdx := context.GetList().GetSelectionRange() + if err := self.resetIfNecessary(context); err != nil { return err } commitSet := self.getData().SelectedShaSet() - // find the last commit that is copied that's above our position - // if there are none, startIndex = 0 - startIndex := 0 - for index, commit := range commitsList[0:selectedIndex] { - if commitSet.Includes(commit.Sha) { - startIndex = index - } - } + allCommitsCopied := lo.EveryBy(commitsList[startIdx:endIdx+1], func(commit *models.Commit) bool { + return commitSet.Includes(commit.Sha) + }) - for index := startIndex; index <= selectedIndex; index++ { - commit := commitsList[index] - self.getData().Add(commit, commitsList) + // if all selected commits are already copied, we'll uncopy them + if allCommitsCopied { + for index := startIdx; index <= endIdx; index++ { + commit := commitsList[index] + self.getData().Remove(commit, commitsList) + } + } else { + for index := startIdx; index <= endIdx; index++ { + commit := commitsList[index] + self.getData().Add(commit, commitsList) + } } return self.rerender() |