From 2dc5e6d50356846fa30cd72f442452a7db9b1203 Mon Sep 17 00:00:00 2001 From: KOREAN139 Date: Wed, 26 Dec 2018 20:39:16 +0900 Subject: [PATCH] Fix recent repo view size issue getMessageHeight() calculates height under assumption that given view's wrap option (view.Wrap) is true, and createMenu() does not set wrap option as true. this causes gocui set improper view's height when lines in view needs to be wrapped. add *gocui.View as parameter in getMessageHeight(), and calculates view's height depend on its wrap option. resolve issue #354 --- pkg/gui/confirmation_panel.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index cdb01466a..36c0a017e 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -37,11 +37,16 @@ func (gui *Gui) closeConfirmationPrompt(g *gocui.Gui) error { return g.DeleteView("confirmation") } -func (gui *Gui) getMessageHeight(message string, width int) int { +func (gui *Gui) getMessageHeight(v *gocui.View, message string, width int) int { lines := strings.Split(message, "\n") lineCount := 0 - for _, line := range lines { - lineCount += len(line)/width + 1 + // if we need to wrap, calculate height to fit content within view's width + if v.Wrap { + for _, line := range lines { + lineCount += len(line)/width + 1 + } + } else { + lineCount = len(lines) } return lineCount } @@ -49,7 +54,8 @@ func (gui *Gui) getMessageHeight(message string, width int) int { func (gui *Gui) getConfirmationPanelDimensions(g *gocui.Gui, prompt string) (int, int, int, int) { width, height := g.Size() panelWidth := width / 2 - panelHeight := gui.getMessageHeight(prompt, panelWidth) + view := g.CurrentView() + panelHeight := gui.getMessageHeight(view, prompt, panelWidth) return width/2 - panelWidth/2, height/2 - panelHeight/2 - panelHeight%2 - 1, width/2 + panelWidth/2,