diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index 5b51dc74e..65ac9a936 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -113,10 +113,6 @@ func (gui *Gui) handleEditCommitFile(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleToggleFileForPatch(g *gocui.Gui, v *gocui.View) error { - if ok, err := gui.validateNormalWorkingTreeState(); !ok { - return err - } - commitFile := gui.getSelectedCommitFile() if commitFile == nil { gui.renderString("commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) @@ -172,10 +168,6 @@ func (gui *Gui) handleEnterCommitFile(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) enterCommitFile(selectedLineIdx int) error { - if ok, err := gui.validateNormalWorkingTreeState(); !ok { - return err - } - commitFile := gui.getSelectedCommitFile() if commitFile == nil { gui.renderString("commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) diff --git a/pkg/gui/context.go b/pkg/gui/context.go index 7b74d94a3..b198cb7e9 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -343,6 +343,21 @@ func (gui *Gui) viewTabContextMap() map[string][]tabContext { } } +func (gui *Gui) currentContextKeyIgnoringPopups() string { + stack := gui.State.ContextStack + + for i := range stack { + reversedIndex := len(stack) - 1 - i + context := stack[reversedIndex] + kind := stack[reversedIndex].GetKind() + if kind != TEMPORARY_POPUP && kind != PERSISTENT_POPUP { + return context.GetKey() + } + } + + return "" +} + func (gui *Gui) switchContext(c Context) error { gui.g.Update(func(*gocui.Gui) error { // push onto stack diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go index 1eb6cffa7..d2e1ba072 100644 --- a/pkg/gui/patch_options_panel.go +++ b/pkg/gui/patch_options_panel.go @@ -26,7 +26,7 @@ func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error }, } - if gui.GitCommand.PatchManager.CanRebase { + if gui.GitCommand.PatchManager.CanRebase && gui.workingTreeState() == "normal" { menuItems = append(menuItems, []*menuItem{ { displayString: fmt.Sprintf("remove patch from original commit (%s)", gui.GitCommand.PatchManager.To), @@ -74,9 +74,6 @@ func (gui *Gui) getPatchCommitIndex() int { } func (gui *Gui) validateNormalWorkingTreeState() (bool, error) { - if gui.GitCommand.WorkingTreeState() != "normal" { - return false, gui.createErrorPanel(gui.Tr.SLocalize("CantPatchWhileRebasingError")) - } if gui.GitCommand.WorkingTreeState() != "normal" { return false, gui.createErrorPanel(gui.Tr.SLocalize("CantPatchWhileRebasingError")) } @@ -183,5 +180,10 @@ func (gui *Gui) handleApplyPatch(reverse bool) error { func (gui *Gui) handleResetPatch() error { gui.GitCommand.PatchManager.Reset() + if gui.currentContextKeyIgnoringPopups() == MAIN_PATCH_BUILDING_CONTEXT_KEY { + if err := gui.switchContext(gui.Contexts.CommitFiles.Context); err != nil { + return err + } + } return gui.refreshCommitFilesView() }