summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context.go
diff options
context:
space:
mode:
authorSean <seand52@gmail.com>2023-01-21 11:38:14 +0000
committerJesse Duffield <jessedduffield@gmail.com>2023-04-30 13:19:53 +1000
commit9d68b287db57b49eddf4b2b81ca1acd2e16aa5aa (patch)
treed286af9a7cfa27348fb5034ee01a1e16a699057b /pkg/gui/context.go
parenta5c72d056ddbd639db3597ffb19a60e0cbae1826 (diff)
Split commit message panel into commit summary and commit description panel
When we use the one panel for the entire commit message, its tricky to have a keybinding both for adding a newline and submitting. By having two panels: one for the summary line and one for the description, we allow for 'enter' to submit the message when done from the summary panel, and 'enter' to add a newline when done from the description panel. Alt-enter, for those who can use that key combo, also works for submitting the message from the description panel. For those who can't use that key combo, and don't want to remap the keybinding, they can hit tab to go back to the summary panel and then 'enter' to submit the message. We have some awkwardness in that both contexts (i.e. panels) need to appear and disappear in tandem and we don't have a great way of handling that concept, so we just push both contexts one after the other, and likewise remove both contexts when we escape.
Diffstat (limited to 'pkg/gui/context.go')
-rw-r--r--pkg/gui/context.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index 28dc5e2b2..252815e18 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -7,6 +7,7 @@ import (
"github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
+ "github.com/samber/lo"
)
// This file is for the management of contexts. There is a context stack such that
@@ -164,6 +165,36 @@ func (self *ContextMgr) Pop() error {
return self.activateContext(newContext, types.OnFocusOpts{})
}
+func (self *ContextMgr) RemoveContexts(contextsToRemove []types.Context) error {
+ self.Lock()
+
+ if len(self.ContextStack) == 1 {
+ self.Unlock()
+ return nil
+ }
+
+ rest := lo.Filter(self.ContextStack, func(context types.Context, _ int) bool {
+ for _, contextToRemove := range contextsToRemove {
+ if context.GetKey() == contextToRemove.GetKey() {
+ return false
+ }
+ }
+ return true
+ })
+ self.ContextStack = rest
+ contextToActivate := rest[len(rest)-1]
+ self.Unlock()
+
+ for _, context := range contextsToRemove {
+ if err := self.deactivateContext(context, types.OnFocusLostOpts{NewContextKey: contextToActivate.GetKey()}); err != nil {
+ return err
+ }
+ }
+
+ // activate the item at the top of the stack
+ return self.activateContext(contextToActivate, types.OnFocusOpts{})
+}
+
func (self *ContextMgr) deactivateContext(c types.Context, opts types.OnFocusLostOpts) error {
view, _ := self.gui.c.GocuiGui().View(c.GetViewName())