diff --git a/pkg/gui/controllers/helpers/confirmation_helper.go b/pkg/gui/controllers/helpers/confirmation_helper.go index 83e4102ac..c0fb5bafb 100644 --- a/pkg/gui/controllers/helpers/confirmation_helper.go +++ b/pkg/gui/controllers/helpers/confirmation_helper.go @@ -116,15 +116,23 @@ func wrapMessageToWidth(wrap bool, message string, width int) []string { return wrappedLines } -func (self *ConfirmationHelper) getPopupPanelDimensionsForContentHeight(panelWidth, contentHeight int) (int, int, int, int) { - return self.getPopupPanelDimensionsAux(panelWidth, contentHeight) +func (self *ConfirmationHelper) getPopupPanelDimensionsForContentHeight(panelWidth, contentHeight int, parentPopupContext types.Context) (int, int, int, int) { + return self.getPopupPanelDimensionsAux(panelWidth, contentHeight, parentPopupContext) } -func (self *ConfirmationHelper) getPopupPanelDimensionsAux(panelWidth int, panelHeight int) (int, int, int, int) { +func (self *ConfirmationHelper) getPopupPanelDimensionsAux(panelWidth int, panelHeight int, parentPopupContext types.Context) (int, int, int, int) { width, height := self.c.GocuiGui().Size() if panelHeight > height*3/4 { panelHeight = height * 3 / 4 } + if parentPopupContext != nil { + // If there's already a popup on the screen, offset the new one from its + // parent so that it's clearly distinguished from the parent + x0, y0, _, _ := parentPopupContext.GetView().Dimensions() + x0 += 2 + y0 += 1 + return x0, y0, x0 + panelWidth, y0 + panelHeight + 1 + } return width/2 - panelWidth/2, height/2 - panelHeight/2 - panelHeight%2 - 1, width/2 + panelWidth/2, @@ -316,19 +324,22 @@ func (self *ConfirmationHelper) getSelectedSuggestionValue() string { } func (self *ConfirmationHelper) ResizeCurrentPopupPanels() { + var parentPopupContext types.Context for _, c := range self.c.CurrentPopupContexts() { switch c { case self.c.Contexts().Menu: - self.resizeMenu() + self.resizeMenu(parentPopupContext) case self.c.Contexts().Confirmation, self.c.Contexts().Suggestions: - self.resizeConfirmationPanel() + self.resizeConfirmationPanel(parentPopupContext) case self.c.Contexts().CommitMessage, self.c.Contexts().CommitDescription: - self.ResizeCommitMessagePanels() + self.ResizeCommitMessagePanels(parentPopupContext) } + + parentPopupContext = c } } -func (self *ConfirmationHelper) resizeMenu() { +func (self *ConfirmationHelper) resizeMenu(parentPopupContext types.Context) { // we want the unfiltered length here so that if we're filtering we don't // resize the window itemCount := self.c.Contexts().Menu.UnfilteredLen() @@ -336,7 +347,7 @@ func (self *ConfirmationHelper) resizeMenu() { panelWidth := self.getPopupPanelWidth() contentWidth := panelWidth - 2 // minus 2 for the frame promptLinesCount := self.layoutMenuPrompt(contentWidth) - x0, y0, x1, y1 := self.getPopupPanelDimensionsForContentHeight(panelWidth, itemCount+offset+promptLinesCount) + x0, y0, x1, y1 := self.getPopupPanelDimensionsForContentHeight(panelWidth, itemCount+offset+promptLinesCount, parentPopupContext) menuBottom := y1 - offset _, _ = self.c.GocuiGui().SetView(self.c.Views().Menu.Name(), x0, y0, x1, menuBottom, 0) @@ -379,7 +390,7 @@ func (self *ConfirmationHelper) layoutMenuPrompt(contentWidth int) int { return len(promptLines) } -func (self *ConfirmationHelper) resizeConfirmationPanel() { +func (self *ConfirmationHelper) resizeConfirmationPanel(parentPopupContext types.Context) { suggestionsViewHeight := 0 if self.c.Views().Suggestions.Visible { suggestionsViewHeight = 11 @@ -392,7 +403,7 @@ func (self *ConfirmationHelper) resizeConfirmationPanel() { wrap = false } panelHeight := getMessageHeight(wrap, prompt, panelWidth) + suggestionsViewHeight - x0, y0, x1, y1 := self.getPopupPanelDimensionsAux(panelWidth, panelHeight) + x0, y0, x1, y1 := self.getPopupPanelDimensionsAux(panelWidth, panelHeight, parentPopupContext) confirmationViewBottom := y1 - suggestionsViewHeight _, _ = self.c.GocuiGui().SetView(self.c.Views().Confirmation.Name(), x0, y0, x1, confirmationViewBottom, 0) @@ -400,7 +411,7 @@ func (self *ConfirmationHelper) resizeConfirmationPanel() { _, _ = self.c.GocuiGui().SetView(self.c.Views().Suggestions.Name(), x0, suggestionsViewTop, x1, suggestionsViewTop+suggestionsViewHeight, 0) } -func (self *ConfirmationHelper) ResizeCommitMessagePanels() { +func (self *ConfirmationHelper) ResizeCommitMessagePanels(parentPopupContext types.Context) { panelWidth := self.getPopupPanelWidth() content := self.c.Views().CommitDescription.TextArea.GetContent() summaryViewHeight := 3 @@ -409,7 +420,7 @@ func (self *ConfirmationHelper) ResizeCommitMessagePanels() { if panelHeight < minHeight { panelHeight = minHeight } - x0, y0, x1, y1 := self.getPopupPanelDimensionsAux(panelWidth, panelHeight) + x0, y0, x1, y1 := self.getPopupPanelDimensionsAux(panelWidth, panelHeight, parentPopupContext) _, _ = self.c.GocuiGui().SetView(self.c.Views().CommitMessage.Name(), x0, y0, x1, y0+summaryViewHeight-1, 0) _, _ = self.c.GocuiGui().SetView(self.c.Views().CommitDescription.Name(), x0, y0+summaryViewHeight, x1, y1+summaryViewHeight, 0)