1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-21 21:47:32 +02:00

Directly send wrap argument rather than the view

This commit is contained in:
Jesse Duffield 2019-01-15 19:33:42 +11:00
parent a38d1a3b68
commit 695b092c41
3 changed files with 7 additions and 11 deletions

View File

@ -37,11 +37,11 @@ func (gui *Gui) closeConfirmationPrompt(g *gocui.Gui) error {
return g.DeleteView("confirmation")
}
func (gui *Gui) getMessageHeight(v *gocui.View, message string, width int) int {
func (gui *Gui) getMessageHeight(wrap bool, message string, width int) int {
lines := strings.Split(message, "\n")
lineCount := 0
// if we need to wrap, calculate height to fit content within view's width
if v.Wrap {
if wrap {
for _, line := range lines {
lineCount += len(line)/width + 1
}
@ -51,14 +51,10 @@ func (gui *Gui) getMessageHeight(v *gocui.View, message string, width int) int {
return lineCount
}
func (gui *Gui) getConfirmationPanelDimensions(g *gocui.Gui, prompt string) (int, int, int, int) {
func (gui *Gui) getConfirmationPanelDimensions(g *gocui.Gui, wrap bool, prompt string) (int, int, int, int) {
width, height := g.Size()
panelWidth := width / 2
view, err := gui.g.View("confirmation")
if err != nil { // confirmation panel was deleted so we just return empty values
return 0,0,0,0
}
panelHeight := gui.getMessageHeight(view, prompt, panelWidth)
panelHeight := gui.getMessageHeight(wrap, prompt, panelWidth)
return width/2 - panelWidth/2,
height/2 - panelHeight/2 - panelHeight%2 - 1,
width/2 + panelWidth/2,
@ -76,7 +72,7 @@ func (gui *Gui) createPromptPanel(g *gocui.Gui, currentView *gocui.View, title s
}
func (gui *Gui) prepareConfirmationPanel(currentView *gocui.View, title, prompt string) (*gocui.View, error) {
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(gui.g, prompt)
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(gui.g, true, prompt)
confirmationView, err := gui.g.SetView("confirmation", x0, y0, x1, y1, 0)
if err != nil {
if err != gocui.ErrUnknownView {

View File

@ -56,7 +56,7 @@ func (gui *Gui) createMenu(items interface{}, handlePress func(int) error) error
return err
}
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(gui.g, list)
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(gui.g, false, list)
menuView, _ := gui.g.SetView("menu", x0, y0, x1, y1, 0)
menuView.Title = strings.Title(gui.Tr.SLocalize("menu"))
menuView.FgColor = gocui.ColorWhite

View File

@ -317,7 +317,7 @@ func (gui *Gui) resizePopupPanel(g *gocui.Gui, v *gocui.View) error {
// If the confirmation panel is already displayed, just resize the width,
// otherwise continue
content := v.Buffer()
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(g, content)
x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(g, v.Wrap, content)
vx0, vy0, vx1, vy1 := v.Dimensions()
if vx0 == x0 && vy0 == y0 && vx1 == x1 && vy1 == y1 {
return nil