1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-04 22:34:39 +02:00

more work on managing focus when applying patch command

This commit is contained in:
Jesse Duffield 2019-11-05 17:57:59 +11:00
parent 1a38bfb76d
commit 10fe88a2cf
5 changed files with 40 additions and 12 deletions

View File

@ -96,6 +96,10 @@ func (gui *Gui) refreshCommitFilesView() error {
return err
}
if err := gui.refreshPatchBuildingPanel(); err != nil {
return err
}
commit := gui.getSelectedCommit(gui.g)
if commit == nil {
return nil

View File

@ -85,7 +85,7 @@ func (gui *Gui) refreshCommits(g *gocui.Gui) error {
if g.CurrentView() == v {
gui.handleCommitSelect(g, v)
}
if g.CurrentView() == gui.getCommitFilesView() {
if g.CurrentView() == gui.getCommitFilesView() || (g.CurrentView() == gui.getMainView() || gui.State.Contexts["main"] == "patch-building") {
return gui.refreshCommitFilesView()
}
return nil

View File

@ -277,8 +277,10 @@ func (gui *Gui) onFocusLost(v *gocui.View, newView *gocui.View) error {
return err
}
case "commitFiles":
if _, err := gui.g.SetViewOnBottom(v.Name()); err != nil {
return err
if gui.State.Contexts["main"] != "patch-building" {
if _, err := gui.g.SetViewOnBottom(v.Name()); err != nil {
return err
}
}
}
gui.Log.Info(v.Name() + " focus lost")

View File

@ -5,6 +5,10 @@ import (
)
func (gui *Gui) refreshPatchBuildingPanel() error {
if gui.GitCommand.PatchManager == nil {
return gui.handleEscapePatchBuildingPanel(gui.g, nil)
}
gui.State.SplitMainPanel = true
// get diff from commit file that's currently selected
@ -23,8 +27,6 @@ func (gui *Gui) refreshPatchBuildingPanel() error {
return err
}
gui.Log.Warn(secondaryDiff)
empty, err := gui.refreshLineByLinePanel(diff, secondaryDiff, false)
if err != nil {
return err
@ -83,6 +85,7 @@ func (gui *Gui) handleRemoveSelectionFromPatch(g *gocui.Gui, v *gocui.View) erro
func (gui *Gui) handleEscapePatchBuildingPanel(g *gocui.Gui, v *gocui.View) error {
gui.State.Panels.LineByLine = nil
gui.State.Contexts["main"] = "normal"
return gui.switchFocus(gui.g, nil, gui.getCommitFilesView())
}

View File

@ -60,11 +60,29 @@ func (gui *Gui) getPatchCommitIndex() int {
return -1
}
func (gui *Gui) validateNormalWorkingTreeState() (bool, error) {
if gui.State.WorkingTreeState != "normal" {
return false, gui.createErrorPanel(gui.g, gui.Tr.SLocalize("CantPatchWhileRebasingError"))
}
return true, nil
}
func (gui *Gui) returnFocusFromLineByLinePanelIfNecessary() error {
if gui.State.Contexts["main"] == "patch-building" {
return gui.handleEscapePatchBuildingPanel(gui.g, nil)
}
return nil
}
func (gui *Gui) handleDeletePatchFromCommit() error {
if ok, err := gui.validateNormalWorkingTreeState(); !ok {
return err
}
if err := gui.returnFocusFromLineByLinePanelIfNecessary(); err != nil {
return err
}
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
commitIndex := gui.getPatchCommitIndex()
err := gui.GitCommand.DeletePatchesFromCommit(gui.State.Commits, commitIndex, gui.GitCommand.PatchManager)
@ -77,6 +95,10 @@ func (gui *Gui) handleMovePatchToSelectedCommit() error {
return err
}
if err := gui.returnFocusFromLineByLinePanelIfNecessary(); err != nil {
return err
}
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
commitIndex := gui.getPatchCommitIndex()
err := gui.GitCommand.MovePatchToSelectedCommit(gui.State.Commits, commitIndex, gui.State.Panels.Commits.SelectedLine, gui.GitCommand.PatchManager)
@ -84,18 +106,15 @@ func (gui *Gui) handleMovePatchToSelectedCommit() error {
})
}
func (gui *Gui) validateNormalWorkingTreeState() (bool, error) {
if gui.State.WorkingTreeState != "normal" {
return false, gui.createErrorPanel(gui.g, gui.Tr.SLocalize("CantPatchWhileRebasingError"))
}
return true, nil
}
func (gui *Gui) handlePullPatchIntoWorkingTree() error {
if ok, err := gui.validateNormalWorkingTreeState(); !ok {
return err
}
if err := gui.returnFocusFromLineByLinePanelIfNecessary(); err != nil {
return err
}
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
commitIndex := gui.getPatchCommitIndex()
err := gui.GitCommand.PullPatchIntoIndex(gui.State.Commits, commitIndex, gui.GitCommand.PatchManager)