summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-09-25 19:03:29 +1000
committerGitHub <noreply@github.com>2018-09-25 19:03:29 +1000
commite9245cd53b462d1295467087635cdee2ed1aabb1 (patch)
tree3f19bb14a0e4175fd453a8eb46a20a7ee22bd5a0 /pkg
parent360b7c1def1f5945f30d89e393bdd4233f0c3179 (diff)
parent80d6bbef8661932ee0a665961b44a681c811ac36 (diff)
Merge branch 'master' into add-tests-part-7
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/git.go1
-rw-r--r--pkg/gui/commit_message_panel.go4
-rw-r--r--pkg/gui/status_panel.go19
-rw-r--r--pkg/gui/view_helpers.go13
-rw-r--r--pkg/utils/utils.go10
-rw-r--r--pkg/utils/utils_test.go35
6 files changed, 71 insertions, 11 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index d9effbef5..720cfea04 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -101,6 +101,7 @@ func NewGitCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Localizer)
Repo: repo,
getGlobalGitConfig: gitconfig.Global,
getLocalGitConfig: gitconfig.Local,
+ removeFile: os.RemoveAll,
}, nil
}
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/status_panel.go b/pkg/gui/status_panel.go
index 6948e9678..89b3e997e 100644
--- a/pkg/gui/status_panel.go
+++ b/pkg/gui/status_panel.go
@@ -2,6 +2,7 @@ package gui
import (
"fmt"
+ "strings"
"github.com/fatih/color"
"github.com/jesseduffield/gocui"
@@ -51,14 +52,16 @@ func (gui *Gui) handleCheckForUpdate(g *gocui.Gui, v *gocui.View) error {
}
func (gui *Gui) handleStatusSelect(g *gocui.Gui, v *gocui.View) error {
- dashboardString := fmt.Sprintf(
- "%s\n\n%s\n\n%s\n\n%s\n\n%s",
- lazygitTitle(),
- "Keybindings: https://github.com/jesseduffield/lazygit/blob/master/docs/Keybindings.md",
- "Config Options: https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md",
- "Tutorial: https://www.youtube.com/watch?v=VDXvbHZYeKY",
- "Raise an Issue: https://github.com/jesseduffield/lazygit/issues",
- )
+ dashboardString := strings.Join(
+ []string{
+ lazygitTitle(),
+ "Copyright (c) 2018 Jesse Duffield",
+ "Keybindings: https://github.com/jesseduffield/lazygit/blob/master/docs/Keybindings.md",
+ "Config Options: https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md",
+ "Tutorial: https://www.youtube.com/watch?v=VDXvbHZYeKY",
+ "Raise an Issue: https://github.com/jesseduffield/lazygit/issues",
+ "Buy Jesse a coffee: https://donorbox.org/lazygit",
+ }, "\n\n")
if err := gui.renderString(g, "main", dashboardString); err != nil {
return err
diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go
index 5178bd4d9..6c3e5505c 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",
@@ -183,7 +190,7 @@ func (gui *Gui) cursorDown(g *gocui.Gui, v *gocui.View) error {
}
cx, cy := v.Cursor()
ox, oy := v.Origin()
- ly := len(v.BufferLines()) - 1
+ ly := v.LinesHeight() - 1
_, height := v.Size()
maxY := height - 1
@@ -219,7 +226,7 @@ func (gui *Gui) correctCursor(v *gocui.View) error {
ox, oy := v.Origin()
_, height := v.Size()
maxY := height - 1
- ly := len(v.BufferLines()) - 1
+ ly := v.LinesHeight() - 1
if oy+cy <= ly {
return nil
}
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))
+ }
+}