mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-13 00:07:59 +02:00
better popup resizing logic
This commit is contained in:
parent
f257740ea7
commit
22d98249fe
@ -130,13 +130,6 @@ func (gui *Gui) prepareConfirmationPanel(
|
|||||||
editable bool,
|
editable bool,
|
||||||
mask bool,
|
mask bool,
|
||||||
) error {
|
) error {
|
||||||
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(true, prompt)
|
|
||||||
// calling SetView on an existing view returns the same view, so I'm not bothering
|
|
||||||
// to reassign to gui.Views.Confirmation
|
|
||||||
_, err := gui.g.SetView("confirmation", x0, y0, x1, y1, 0)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
gui.Views.Confirmation.HasLoader = hasLoader
|
gui.Views.Confirmation.HasLoader = hasLoader
|
||||||
if hasLoader {
|
if hasLoader {
|
||||||
gui.g.StartTicking()
|
gui.g.StartTicking()
|
||||||
@ -149,11 +142,7 @@ func (gui *Gui) prepareConfirmationPanel(
|
|||||||
|
|
||||||
gui.findSuggestions = findSuggestionsFunc
|
gui.findSuggestions = findSuggestionsFunc
|
||||||
if findSuggestionsFunc != nil {
|
if findSuggestionsFunc != nil {
|
||||||
suggestionsViewHeight := 11
|
suggestionsView := gui.Views.Suggestions
|
||||||
suggestionsView, err := gui.g.SetView("suggestions", x0, y1+1, x1, y1+suggestionsViewHeight, 0)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
suggestionsView.Wrap = false
|
suggestionsView.Wrap = false
|
||||||
suggestionsView.FgColor = theme.GocuiDefaultTextColor
|
suggestionsView.FgColor = theme.GocuiDefaultTextColor
|
||||||
gui.setSuggestions(findSuggestionsFunc(""))
|
gui.setSuggestions(findSuggestionsFunc(""))
|
||||||
|
@ -59,16 +59,3 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error {
|
|||||||
// TODO: ensure that if we're opened a menu from within a menu that it renders correctly
|
// TODO: ensure that if we're opened a menu from within a menu that it renders correctly
|
||||||
return gui.c.PushContext(gui.State.Contexts.Menu)
|
return gui.c.PushContext(gui.State.Contexts.Menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) resizeMenu() {
|
|
||||||
itemCount := gui.State.Contexts.Menu.GetList().Len()
|
|
||||||
offset := 3
|
|
||||||
panelWidth := gui.getConfirmationPanelWidth()
|
|
||||||
x0, y0, x1, y1 := gui.getConfirmationPanelDimensionsForContentHeight(panelWidth, itemCount+offset)
|
|
||||||
menuBottom := y1 - offset
|
|
||||||
_, _ = gui.g.SetView("menu", x0, y0, x1, menuBottom, 0)
|
|
||||||
|
|
||||||
tooltipTop := menuBottom + 1
|
|
||||||
tooltipHeight := gui.getMessageHeight(true, gui.State.Contexts.Menu.GetSelected().Tooltip, panelWidth) + 2 // plus 2 for the frame
|
|
||||||
_, _ = gui.g.SetView("tooltip", x0, tooltipTop, x1, tooltipTop+tooltipHeight-1, 0)
|
|
||||||
}
|
|
||||||
|
@ -50,6 +50,8 @@ func (gui *Gui) resizeCurrentPopupPanel() error {
|
|||||||
|
|
||||||
if v == gui.Views.Menu {
|
if v == gui.Views.Menu {
|
||||||
gui.resizeMenu()
|
gui.resizeMenu()
|
||||||
|
} else if v == gui.Views.Confirmation || v == gui.Views.Suggestions {
|
||||||
|
gui.resizeConfirmationPanel()
|
||||||
} else if gui.isPopupPanel(v.Name()) {
|
} else if gui.isPopupPanel(v.Name()) {
|
||||||
return gui.resizePopupPanel(v, v.Buffer())
|
return gui.resizePopupPanel(v, v.Buffer())
|
||||||
}
|
}
|
||||||
@ -58,17 +60,40 @@ func (gui *Gui) resizeCurrentPopupPanel() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) resizePopupPanel(v *gocui.View, content string) error {
|
func (gui *Gui) resizePopupPanel(v *gocui.View, content string) error {
|
||||||
// If the confirmation panel is already displayed, just resize the width,
|
|
||||||
// otherwise continue
|
|
||||||
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(v.Wrap, content)
|
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(v.Wrap, content)
|
||||||
vx0, vy0, vx1, vy1 := v.Dimensions()
|
|
||||||
if vx0 == x0 && vy0 == y0 && vx1 == x1 && vy1 == y1 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
_, err := gui.g.SetView(v.Name(), x0, y0, x1, y1, 0)
|
_, err := gui.g.SetView(v.Name(), x0, y0, x1, y1, 0)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) resizeMenu() {
|
||||||
|
itemCount := gui.State.Contexts.Menu.GetList().Len()
|
||||||
|
offset := 3
|
||||||
|
panelWidth := gui.getConfirmationPanelWidth()
|
||||||
|
x0, y0, x1, y1 := gui.getConfirmationPanelDimensionsForContentHeight(panelWidth, itemCount+offset)
|
||||||
|
menuBottom := y1 - offset
|
||||||
|
_, _ = gui.g.SetView(gui.Views.Menu.Name(), x0, y0, x1, menuBottom, 0)
|
||||||
|
|
||||||
|
tooltipTop := menuBottom + 1
|
||||||
|
tooltipHeight := gui.getMessageHeight(true, gui.State.Contexts.Menu.GetSelected().Tooltip, panelWidth) + 2 // plus 2 for the frame
|
||||||
|
_, _ = gui.g.SetView(gui.Views.Tooltip.Name(), x0, tooltipTop, x1, tooltipTop+tooltipHeight-1, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) resizeConfirmationPanel() {
|
||||||
|
suggestionsViewHeight := 0
|
||||||
|
if gui.Views.Suggestions.Visible {
|
||||||
|
suggestionsViewHeight = 11
|
||||||
|
}
|
||||||
|
panelWidth := gui.getConfirmationPanelWidth()
|
||||||
|
prompt := gui.Views.Confirmation.Buffer()
|
||||||
|
panelHeight := gui.getMessageHeight(true, prompt, panelWidth) + suggestionsViewHeight
|
||||||
|
x0, y0, x1, y1 := gui.getConfirmationPanelDimensionsAux(panelWidth, panelHeight)
|
||||||
|
confirmationViewBottom := y1 - suggestionsViewHeight
|
||||||
|
_, _ = gui.g.SetView(gui.Views.Confirmation.Name(), x0, y0, x1, confirmationViewBottom, 0)
|
||||||
|
|
||||||
|
suggestionsViewTop := confirmationViewBottom + 1
|
||||||
|
_, _ = gui.g.SetView(gui.Views.Suggestions.Name(), x0, suggestionsViewTop, x1, suggestionsViewTop+suggestionsViewHeight, 0)
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) globalOptionsMap() map[string]string {
|
func (gui *Gui) globalOptionsMap() map[string]string {
|
||||||
keybindingConfig := gui.c.UserConfig.Keybinding
|
keybindingConfig := gui.c.UserConfig.Keybinding
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user