summaryrefslogtreecommitdiffstats
path: root/pkg/gui/cherry_picking.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-08-22 11:05:37 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-08-23 14:29:18 +1000
commitfbd61fcd17d495e9605bcf1f765663f861839cac (patch)
treed5d9eaa12e3e5fbefa5c50282af8f8207d5bb6a3 /pkg/gui/cherry_picking.go
parentb1529f19ad527d29a469de09c11c37d7f61d8d16 (diff)
refactor how we handle different modes
Diffstat (limited to 'pkg/gui/cherry_picking.go')
-rw-r--r--pkg/gui/cherry_picking.go44
1 files changed, 28 insertions, 16 deletions
diff --git a/pkg/gui/cherry_picking.go b/pkg/gui/cherry_picking.go
index b1cbf84e5..c87ba7a73 100644
--- a/pkg/gui/cherry_picking.go
+++ b/pkg/gui/cherry_picking.go
@@ -1,40 +1,52 @@
package gui
import (
- "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands"
)
-func (gui *Gui) handleCopyCommit(g *gocui.Gui, v *gocui.View) error {
+// you can only copy from one context at a time, because the order and position of commits matter
+
+func (gui *Gui) handleCopyCommit() error {
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
return err
}
// get currently selected commit, add the sha to state.
- commit := gui.State.Commits[gui.State.Panels.Commits.SelectedLineIdx]
+ context := gui.currentSideContext()
+ if context == nil {
+ return nil
+ }
+
+ commit, ok := context.SelectedItem().(*commands.Commit)
+ if !ok {
+ gui.Log.Error("type cast failed for handling copy commit")
+ }
+ if commit == nil {
+ return nil
+ }
// we will un-copy it if it's already copied
- for index, cherryPickedCommit := range gui.State.CherryPickedCommits {
+ for index, cherryPickedCommit := range gui.State.Modes.CherryPicking.CherryPickedCommits {
if commit.Sha == cherryPickedCommit.Sha {
- gui.State.CherryPickedCommits = append(gui.State.CherryPickedCommits[0:index], gui.State.CherryPickedCommits[index+1:]...)
- return gui.Contexts.BranchCommits.Context.HandleRender()
+ gui.State.Modes.CherryPicking.CherryPickedCommits = append(gui.State.Modes.CherryPicking.CherryPickedCommits[0:index], gui.State.Modes.CherryPicking.CherryPickedCommits[index+1:]...)
+ return context.HandleRender()
}
}
gui.addCommitToCherryPickedCommits(gui.State.Panels.Commits.SelectedLineIdx)
- return gui.Contexts.BranchCommits.Context.HandleRender()
+ return context.HandleRender()
}
-func (gui *Gui) cherryPickedCommitShaMap() map[string]bool {
+func (gui *Gui) CherryPickedCommitShaMap() map[string]bool {
commitShaMap := map[string]bool{}
- for _, commit := range gui.State.CherryPickedCommits {
+ for _, commit := range gui.State.Modes.CherryPicking.CherryPickedCommits {
commitShaMap[commit.Sha] = true
}
return commitShaMap
}
func (gui *Gui) addCommitToCherryPickedCommits(index int) {
- commitShaMap := gui.cherryPickedCommitShaMap()
+ commitShaMap := gui.CherryPickedCommitShaMap()
commitShaMap[gui.State.Commits[index].Sha] = true
newCommits := []*commands.Commit{}
@@ -45,15 +57,15 @@ func (gui *Gui) addCommitToCherryPickedCommits(index int) {
}
}
- gui.State.CherryPickedCommits = newCommits
+ gui.State.Modes.CherryPicking.CherryPickedCommits = newCommits
}
-func (gui *Gui) handleCopyCommitRange(g *gocui.Gui, v *gocui.View) error {
+func (gui *Gui) handleCopyCommitRange() error {
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
return err
}
- commitShaMap := gui.cherryPickedCommitShaMap()
+ commitShaMap := gui.CherryPickedCommitShaMap()
// find the last commit that is copied that's above our position
// if there are none, startIndex = 0
@@ -72,19 +84,19 @@ func (gui *Gui) handleCopyCommitRange(g *gocui.Gui, v *gocui.View) error {
}
// HandlePasteCommits begins a cherry-pick rebase with the commits the user has copied
-func (gui *Gui) HandlePasteCommits(g *gocui.Gui, v *gocui.View) error {
+func (gui *Gui) HandlePasteCommits() error {
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
return err
}
return gui.ask(askOpts{
- returnToView: v,
+ returnToView: gui.getCommitsView(),
returnFocusOnClose: true,
title: gui.Tr.SLocalize("CherryPick"),
prompt: gui.Tr.SLocalize("SureCherryPick"),
handleConfirm: func() error {
return gui.WithWaitingStatus(gui.Tr.SLocalize("CherryPickingStatus"), func() error {
- err := gui.GitCommand.CherryPickCommits(gui.State.CherryPickedCommits)
+ err := gui.GitCommand.CherryPickCommits(gui.State.Modes.CherryPicking.CherryPickedCommits)
return gui.handleGenericMergeCommandResult(err)
})
},