summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-03-24 22:07:30 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-03-26 18:00:46 +1100
commit13b90ac37f40baa648c25fab6d299ae0fa59118b (patch)
tree61dd23273a4b32c3c8d191759cc0ce3ae9d7c08a /pkg/gui/context.go
parente039429885996f1335430a856b846d8dc6279325 (diff)
support viewing commits of reflog entry and show better view title
Diffstat (limited to 'pkg/gui/context.go')
-rw-r--r--pkg/gui/context.go33
1 files changed, 26 insertions, 7 deletions
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index e75eb0a05..c02411640 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -11,6 +11,7 @@ import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
+ "github.com/samber/lo"
)
func (gui *Gui) popupViewNames() []string {
@@ -99,8 +100,6 @@ func (gui *Gui) pushContext(c types.Context, opts ...types.OnFocusOpts) error {
return gui.activateContext(c, opts...)
}
-// asynchronous code idea: functions return an error via a channel, when done
-
// pushContextWithView is to be used when you don't know which context you
// want to switch to: you only know the view that you want to switch to. It will
// look up the context currently active for that view and switch to that context
@@ -136,6 +135,10 @@ func (gui *Gui) returnFromContext() error {
}
func (gui *Gui) deactivateContext(c types.Context) error {
+ if c.IsTransient() {
+ gui.resetWindowContext(c)
+ }
+
view, _ := gui.g.View(c.GetViewName())
if view != nil && view.IsSearching() {
@@ -145,7 +148,11 @@ func (gui *Gui) deactivateContext(c types.Context) error {
}
// if we are the kind of context that is sent to back upon deactivation, we should do that
- if view != nil && (c.GetKind() == types.TEMPORARY_POPUP || c.GetKind() == types.PERSISTENT_POPUP || c.GetKey() == context.COMMIT_FILES_CONTEXT_KEY) {
+ if view != nil &&
+ (c.GetKind() == types.TEMPORARY_POPUP ||
+ c.GetKind() == types.PERSISTENT_POPUP ||
+ c.GetKey() == context.COMMIT_FILES_CONTEXT_KEY ||
+ c.GetKey() == context.SUB_COMMITS_CONTEXT_KEY) {
view.Visible = false
}
@@ -204,6 +211,11 @@ func (gui *Gui) activateContext(c types.Context, opts ...types.OnFocusOpts) erro
return err
}
+ desiredTitle := c.Title()
+ if desiredTitle != "" {
+ v.Title = desiredTitle
+ }
+
v.Visible = true
// if the new context's view was previously displaying another context, render the new context
@@ -380,10 +392,17 @@ func (gui *Gui) onViewFocusLost(oldView *gocui.View, newView *gocui.View) error
_ = oldView.SetOriginX(0)
- if oldView == gui.Views.CommitFiles && newView != gui.Views.Main && newView != gui.Views.Secondary && newView != gui.Views.Search {
- gui.resetWindowContext(gui.State.Contexts.CommitFiles)
- if err := gui.deactivateContext(gui.State.Contexts.CommitFiles); err != nil {
- return err
+ if !lo.Contains([]*gocui.View{gui.Views.Main, gui.Views.Secondary, gui.Views.Search}, newView) {
+ transientContexts := slices.Filter(gui.State.Contexts.Flatten(), func(context types.Context) bool {
+ return context.IsTransient()
+ })
+
+ for _, context := range transientContexts {
+ if oldView.Name() == context.GetViewName() {
+ if err := gui.deactivateContext(context); err != nil {
+ return err
+ }
+ }
}
}