diff options
author | KOREAN139 <korean139@gmail.com> | 2018-12-26 20:39:16 +0900 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-01-17 10:29:52 +1100 |
commit | 2dc5e6d50356846fa30cd72f442452a7db9b1203 (patch) | |
tree | 05b76f9c593f21281aa3d9fa156bd8151990ea8e | |
parent | 0dcfa09ff25384be1b926af85ba9a9a956681db4 (diff) |
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
-rw-r--r-- | pkg/gui/confirmation_panel.go | 14 |
1 files 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, |