summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2024-01-13 17:40:28 +1100
committerJesse Duffield <jessedduffield@gmail.com>2024-01-19 10:50:49 +1100
commit280b4d60f893a0e20897091ab02617c32180b45d (patch)
tree9665a327ae7fe4d468637fc0e10327a223a113ed /pkg/gui
parent54bd94ad24ca24ca12fab59e9dbf0d79fe7681da (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')
-rw-r--r--pkg/gui/controllers/basic_commits_controller.go14
-rw-r--r--pkg/gui/controllers/helpers/cherry_pick_helper.go30
2 files changed, 21 insertions, 23 deletions
diff --git a/pkg/gui/controllers/basic_commits_controller.go b/pkg/gui/controllers/basic_commits_controller.go
index 551349466..2f120a0f4 100644
--- a/pkg/gui/controllers/basic_commits_controller.go
+++ b/pkg/gui/controllers/basic_commits_controller.go
@@ -14,6 +14,7 @@ var _ types.IController = &BasicCommitsController{}
type ContainsCommits interface {
types.Context
+ types.IListContext
GetSelected() *models.Commit
GetCommits() []*models.Commit
GetSelectedLineIdx() int
@@ -64,13 +65,8 @@ func (self *BasicCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
},
{
Key: opts.GetKey(opts.Config.Commits.CherryPickCopy),
- Handler: self.checkSelected(self.copy),
- Description: self.c.Tr.CherryPickCopy,
- },
- {
- Key: opts.GetKey(opts.Config.Commits.CherryPickCopyRange),
Handler: self.checkSelected(self.copyRange),
- Description: self.c.Tr.CherryPickCopyRange,
+ Description: self.c.Tr.CherryPickCopy,
},
{
Key: opts.GetKey(opts.Config.Commits.ResetCherryPick),
@@ -271,12 +267,8 @@ func (self *BasicCommitsController) checkout(commit *models.Commit) error {
})
}
-func (self *BasicCommitsController) copy(commit *models.Commit) error {
- return self.c.Helpers().CherryPick.Copy(commit, self.context.GetCommits(), self.context)
-}
-
func (self *BasicCommitsController) copyRange(*models.Commit) error {
- return self.c.Helpers().CherryPick.CopyRange(self.context.GetSelectedLineIdx(), self.context.GetCommits(), self.context)
+ return self.c.Helpers().CherryPick.CopyRange(self.context.GetCommits(), self.context)
}
func (self *BasicCommitsController) openDiffTool(commit *models.Commit) error {
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()