From b9708c9f8850352d18ef4d10c285698be882f838 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Wed, 19 Sep 2018 20:36:40 +1000 Subject: fix issues with commit message panel losing focus --- pkg/gui/commit_message_panel.go | 4 ++++ pkg/gui/view_helpers.go | 9 ++++++++- pkg/utils/utils.go | 10 ++++++++++ pkg/utils/utils_test.go | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go index e23c47da0..74e02be90 100644 --- a/pkg/gui/commit_message_panel.go +++ b/pkg/gui/commit_message_panel.go @@ -37,6 +37,10 @@ func (gui *Gui) handleCommitClose(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleCommitFocused(g *gocui.Gui, v *gocui.View) error { + if _, err := g.SetViewOnTop("commitMessage"); err != nil { + return err + } + message := gui.Tr.TemplateLocalize( "CloseConfirm", Teml{ diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 5178bd4d9..96a77f3d6 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -133,8 +133,15 @@ func (gui *Gui) switchFocus(g *gocui.Gui, oldView, newView *gocui.View) error { }, ) gui.Log.Info(message) - gui.State.PreviousView = oldView.Name() + + // second class panels should never have focus restored to them because + // once they lose focus they are effectively 'destroyed' + secondClassPanels := []string{"confirmation", "menu"} + if !utils.IncludesString(secondClassPanels, oldView.Name()) { + gui.State.PreviousView = oldView.Name() + } } + newView.Highlight = true message := gui.Tr.TemplateLocalize( "newFocusedViewIs", diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index aef653c50..8e481b3a4 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -204,3 +204,13 @@ func getDisplayStringArrays(displayables []Displayable) [][]string { } return stringArrays } + +// IncludesString if the list contains the string +func IncludesString(list []string, a string) bool { + for _, b := range list { + if b == a { + return true + } + } + return false +} diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go index 918031512..21e1d5031 100644 --- a/pkg/utils/utils_test.go +++ b/pkg/utils/utils_test.go @@ -376,3 +376,38 @@ func TestMin(t *testing.T) { assert.EqualValues(t, s.expected, Min(s.a, s.b)) } } + +func TestIncludesString(t *testing.T) { + type scenario struct { + list []string + element string + expected bool + } + + scenarios := []scenario{ + { + []string{"a", "b"}, + "a", + true, + }, + { + []string{"a", "b"}, + "c", + false, + }, + { + []string{"a", "b"}, + "", + false, + }, + { + []string{""}, + "", + true, + }, + } + + for _, s := range scenarios { + assert.EqualValues(t, s.expected, IncludesString(s.list, s.element)) + } +} -- cgit v1.2.3