55 "fmt"
66 "strings"
77
8- "github.com/jesseduffield/gocui"
9-
108 "github.com/jesseduffield/lazygit/pkg/gui/style"
119 "github.com/jesseduffield/lazygit/pkg/gui/types"
1210 "github.com/jesseduffield/lazygit/pkg/theme"
@@ -118,21 +116,23 @@ func wrapMessageToWidth(wrap bool, message string, width int) []string {
118116 return wrappedLines
119117}
120118
121- func (self * ConfirmationHelper ) getPopupPanelDimensions (wrap bool , prompt string ) (int , int , int , int ) {
122- panelWidth := self .getPopupPanelWidth ()
123- panelHeight := getMessageHeight (wrap , prompt , panelWidth )
124- return self .getPopupPanelDimensionsAux (panelWidth , panelHeight )
125- }
126-
127- func (self * ConfirmationHelper ) getPopupPanelDimensionsForContentHeight (panelWidth , contentHeight int ) (int , int , int , int ) {
128- return self .getPopupPanelDimensionsAux (panelWidth , contentHeight )
119+ func (self * ConfirmationHelper ) getPopupPanelDimensionsForContentHeight (panelWidth , contentHeight int , parentPopupContext types.Context ) (int , int , int , int ) {
120+ return self .getPopupPanelDimensionsAux (panelWidth , contentHeight , parentPopupContext )
129121}
130122
131- func (self * ConfirmationHelper ) getPopupPanelDimensionsAux (panelWidth int , panelHeight int ) (int , int , int , int ) {
123+ func (self * ConfirmationHelper ) getPopupPanelDimensionsAux (panelWidth int , panelHeight int , parentPopupContext types. Context ) (int , int , int , int ) {
132124 width , height := self .c .GocuiGui ().Size ()
133125 if panelHeight > height * 3 / 4 {
134126 panelHeight = height * 3 / 4
135127 }
128+ if parentPopupContext != nil {
129+ // If there's already a popup on the screen, offset the new one from its
130+ // parent so that it's clearly distinguished from the parent
131+ x0 , y0 , _ , _ := parentPopupContext .GetView ().Dimensions ()
132+ x0 += 2
133+ y0 += 1
134+ return x0 , y0 , x0 + panelWidth , y0 + panelHeight + 1
135+ }
136136 return width / 2 - panelWidth / 2 ,
137137 height / 2 - panelHeight / 2 - panelHeight % 2 - 1 ,
138138 width / 2 + panelWidth / 2 ,
@@ -177,7 +177,6 @@ func (self *ConfirmationHelper) prepareConfirmationPanel(
177177 suggestionsView .Subtitle = ""
178178 }
179179
180- self .ResizeConfirmationPanel ()
181180 return nil
182181}
183182
@@ -227,7 +226,6 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ
227226 textArea := confirmationView .TextArea
228227 textArea .Clear ()
229228 textArea .TypeString (opts .Prompt )
230- self .ResizeConfirmationPanel ()
231229 confirmationView .RenderTextArea ()
232230 } else {
233231 self .c .ResetViewOrigin (confirmationView )
@@ -325,57 +323,31 @@ func (self *ConfirmationHelper) getSelectedSuggestionValue() string {
325323 return ""
326324}
327325
328- func (self * ConfirmationHelper ) ResizeConfirmationPanel () {
329- suggestionsViewHeight := 0
330- if self .c .Views ().Suggestions .Visible {
331- suggestionsViewHeight = 11
332- }
333- panelWidth := self .getPopupPanelWidth ()
334- prompt := self .c .Views ().Confirmation .Buffer ()
335- wrap := true
336- if self .c .Views ().Confirmation .Editable {
337- prompt = self .c .Views ().Confirmation .TextArea .GetContent ()
338- wrap = false
339- }
340- panelHeight := getMessageHeight (wrap , prompt , panelWidth ) + suggestionsViewHeight
341- x0 , y0 , x1 , y1 := self .getPopupPanelDimensionsAux (panelWidth , panelHeight )
342- confirmationViewBottom := y1 - suggestionsViewHeight
343- _ , _ = self .c .GocuiGui ().SetView (self .c .Views ().Confirmation .Name (), x0 , y0 , x1 , confirmationViewBottom , 0 )
344-
345- suggestionsViewTop := confirmationViewBottom + 1
346- _ , _ = self .c .GocuiGui ().SetView (self .c .Views ().Suggestions .Name (), x0 , suggestionsViewTop , x1 , suggestionsViewTop + suggestionsViewHeight , 0 )
347- }
348-
349- func (self * ConfirmationHelper ) ResizeCurrentPopupPanel () error {
350- c := self .c .CurrentContext ()
326+ func (self * ConfirmationHelper ) ResizeCurrentPopupPanels () {
327+ var parentPopupContext types.Context
328+ for _ , c := range self .c .CurrentPopupContexts () {
329+ switch c {
330+ case self .c .Contexts ().Menu :
331+ self .resizeMenu (parentPopupContext )
332+ case self .c .Contexts ().Confirmation , self .c .Contexts ().Suggestions :
333+ self .resizeConfirmationPanel (parentPopupContext )
334+ case self .c .Contexts ().CommitMessage , self .c .Contexts ().CommitDescription :
335+ self .ResizeCommitMessagePanels (parentPopupContext )
336+ }
351337
352- switch c {
353- case self .c .Contexts ().Menu :
354- self .resizeMenu ()
355- case self .c .Contexts ().Confirmation , self .c .Contexts ().Suggestions :
356- self .resizeConfirmationPanel ()
357- case self .c .Contexts ().CommitMessage , self .c .Contexts ().CommitDescription :
358- self .ResizeCommitMessagePanels ()
338+ parentPopupContext = c
359339 }
360-
361- return nil
362- }
363-
364- func (self * ConfirmationHelper ) ResizePopupPanel (v * gocui.View , content string ) error {
365- x0 , y0 , x1 , y1 := self .getPopupPanelDimensions (v .Wrap , content )
366- _ , err := self .c .GocuiGui ().SetView (v .Name (), x0 , y0 , x1 , y1 , 0 )
367- return err
368340}
369341
370- func (self * ConfirmationHelper ) resizeMenu () {
342+ func (self * ConfirmationHelper ) resizeMenu (parentPopupContext types. Context ) {
371343 // we want the unfiltered length here so that if we're filtering we don't
372344 // resize the window
373345 itemCount := self .c .Contexts ().Menu .UnfilteredLen ()
374346 offset := 3
375347 panelWidth := self .getPopupPanelWidth ()
376348 contentWidth := panelWidth - 2 // minus 2 for the frame
377349 promptLinesCount := self .layoutMenuPrompt (contentWidth )
378- x0 , y0 , x1 , y1 := self .getPopupPanelDimensionsForContentHeight (panelWidth , itemCount + offset + promptLinesCount )
350+ x0 , y0 , x1 , y1 := self .getPopupPanelDimensionsForContentHeight (panelWidth , itemCount + offset + promptLinesCount , parentPopupContext )
379351 menuBottom := y1 - offset
380352 _ , _ = self .c .GocuiGui ().SetView (self .c .Views ().Menu .Name (), x0 , y0 , x1 , menuBottom , 0 )
381353
@@ -418,7 +390,7 @@ func (self *ConfirmationHelper) layoutMenuPrompt(contentWidth int) int {
418390 return len (promptLines )
419391}
420392
421- func (self * ConfirmationHelper ) resizeConfirmationPanel () {
393+ func (self * ConfirmationHelper ) resizeConfirmationPanel (parentPopupContext types. Context ) {
422394 suggestionsViewHeight := 0
423395 if self .c .Views ().Suggestions .Visible {
424396 suggestionsViewHeight = 11
@@ -431,15 +403,15 @@ func (self *ConfirmationHelper) resizeConfirmationPanel() {
431403 wrap = false
432404 }
433405 panelHeight := getMessageHeight (wrap , prompt , panelWidth ) + suggestionsViewHeight
434- x0 , y0 , x1 , y1 := self .getPopupPanelDimensionsAux (panelWidth , panelHeight )
406+ x0 , y0 , x1 , y1 := self .getPopupPanelDimensionsAux (panelWidth , panelHeight , parentPopupContext )
435407 confirmationViewBottom := y1 - suggestionsViewHeight
436408 _ , _ = self .c .GocuiGui ().SetView (self .c .Views ().Confirmation .Name (), x0 , y0 , x1 , confirmationViewBottom , 0 )
437409
438410 suggestionsViewTop := confirmationViewBottom + 1
439411 _ , _ = self .c .GocuiGui ().SetView (self .c .Views ().Suggestions .Name (), x0 , suggestionsViewTop , x1 , suggestionsViewTop + suggestionsViewHeight , 0 )
440412}
441413
442- func (self * ConfirmationHelper ) ResizeCommitMessagePanels () {
414+ func (self * ConfirmationHelper ) ResizeCommitMessagePanels (parentPopupContext types. Context ) {
443415 panelWidth := self .getPopupPanelWidth ()
444416 content := self .c .Views ().CommitDescription .TextArea .GetContent ()
445417 summaryViewHeight := 3
@@ -448,18 +420,18 @@ func (self *ConfirmationHelper) ResizeCommitMessagePanels() {
448420 if panelHeight < minHeight {
449421 panelHeight = minHeight
450422 }
451- x0 , y0 , x1 , y1 := self .getPopupPanelDimensionsAux (panelWidth , panelHeight )
423+ x0 , y0 , x1 , y1 := self .getPopupPanelDimensionsAux (panelWidth , panelHeight , parentPopupContext )
452424
453425 _ , _ = self .c .GocuiGui ().SetView (self .c .Views ().CommitMessage .Name (), x0 , y0 , x1 , y0 + summaryViewHeight - 1 , 0 )
454426 _ , _ = self .c .GocuiGui ().SetView (self .c .Views ().CommitDescription .Name (), x0 , y0 + summaryViewHeight , x1 , y1 + summaryViewHeight , 0 )
455427}
456428
457- func (self * ConfirmationHelper ) IsPopupPanel (viewName string ) bool {
458- return viewName == "commitMessage" || viewName == "confirmation" || viewName == "menu"
429+ func (self * ConfirmationHelper ) IsPopupPanel (context types. Context ) bool {
430+ return context . GetKind () == types . PERSISTENT_POPUP || context . GetKind () == types . TEMPORARY_POPUP
459431}
460432
461433func (self * ConfirmationHelper ) IsPopupPanelFocused () bool {
462- return self .IsPopupPanel (self .c .CurrentContext (). GetViewName () )
434+ return self .IsPopupPanel (self .c .CurrentContext ())
463435}
464436
465437func (self * ConfirmationHelper ) TooltipForMenuItem (menuItem * types.MenuItem ) string {
0 commit comments