From 1ab1fb3599c9aa891e9ff0c8ca52f1a22b8af141 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 25 Jun 2024 19:25:46 +0200 Subject: [PATCH] Resize all open popup panels in layout, not just the topmost one Probably not the most import feature in the world, but when resizing the terminal window while multiple popup panels were open at the same time, we would only resize the topmost one. The main reason for changing this is because it makes the next commit easier to implement. --- pkg/gui/context.go | 9 +++++++++ .../helpers/confirmation_helper.go | 20 +++++++++---------- pkg/gui/gui_common.go | 4 ++++ pkg/gui/layout.go | 2 +- pkg/gui/types/common.go | 1 + 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/pkg/gui/context.go b/pkg/gui/context.go index 28ecf2405..5dc6df6a0 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -391,3 +391,12 @@ func (self *ContextMgr) ContextForKey(key types.ContextKey) types.Context { return nil } + +func (self *ContextMgr) PopupContexts() []types.Context { + self.RLock() + defer self.RUnlock() + + return lo.Filter(self.ContextStack, func(context types.Context, _ int) bool { + return context.GetKind() == types.TEMPORARY_POPUP || context.GetKind() == types.PERSISTENT_POPUP + }) +} diff --git a/pkg/gui/controllers/helpers/confirmation_helper.go b/pkg/gui/controllers/helpers/confirmation_helper.go index 2a1a821c2..83e4102ac 100644 --- a/pkg/gui/controllers/helpers/confirmation_helper.go +++ b/pkg/gui/controllers/helpers/confirmation_helper.go @@ -315,16 +315,16 @@ func (self *ConfirmationHelper) getSelectedSuggestionValue() string { return "" } -func (self *ConfirmationHelper) ResizeCurrentPopupPanel() { - c := self.c.CurrentContext() - - switch c { - case self.c.Contexts().Menu: - self.resizeMenu() - case self.c.Contexts().Confirmation, self.c.Contexts().Suggestions: - self.resizeConfirmationPanel() - case self.c.Contexts().CommitMessage, self.c.Contexts().CommitDescription: - self.ResizeCommitMessagePanels() +func (self *ConfirmationHelper) ResizeCurrentPopupPanels() { + for _, c := range self.c.CurrentPopupContexts() { + switch c { + case self.c.Contexts().Menu: + self.resizeMenu() + case self.c.Contexts().Confirmation, self.c.Contexts().Suggestions: + self.resizeConfirmationPanel() + case self.c.Contexts().CommitMessage, self.c.Contexts().CommitDescription: + self.ResizeCommitMessagePanels() + } } } diff --git a/pkg/gui/gui_common.go b/pkg/gui/gui_common.go index 434f4b38b..8a537f2ca 100644 --- a/pkg/gui/gui_common.go +++ b/pkg/gui/gui_common.go @@ -73,6 +73,10 @@ func (self *guiCommon) CurrentSideContext() types.Context { return self.gui.State.ContextMgr.CurrentSide() } +func (self *guiCommon) CurrentPopupContexts() []types.Context { + return self.gui.State.ContextMgr.PopupContexts() +} + func (self *guiCommon) IsCurrentContext(c types.Context) bool { return self.gui.State.ContextMgr.IsCurrent(c) } diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go index 077ee3c84..3bf6a7c35 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -173,7 +173,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { // if you run `lazygit --logs` // this will let you see these branches as prettified json // gui.c.Log.Info(utils.AsJson(gui.State.Model.Branches[0:4])) - gui.helpers.Confirmation.ResizeCurrentPopupPanel() + gui.helpers.Confirmation.ResizeCurrentPopupPanels() gui.renderContextOptionsMap() diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go index 61c27de49..c6885d717 100644 --- a/pkg/gui/types/common.go +++ b/pkg/gui/types/common.go @@ -67,6 +67,7 @@ type IGuiCommon interface { CurrentContext() Context CurrentStaticContext() Context CurrentSideContext() Context + CurrentPopupContexts() []Context IsCurrentContext(Context) bool // TODO: replace the above context-based methods with just using Context() e.g. replace PushContext() with Context().Push() Context() IContextMgr