From 40724af7e1b024f3ca4c22808c4ec8cdeda3baf0 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Fri, 21 Aug 2020 14:22:20 -0400 Subject: [PATCH] Short circuit help view sooner if we can --- ui/stash.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ui/stash.go b/ui/stash.go index 8cd9512..8a27739 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -706,16 +706,18 @@ func stashHelpView(m stashModel) string { // builds the help view from various sections pieces, truncating it if the view // would otherwise wrap to two lines. func stashHelpViewBuilder(windowWidth int, sections ...string) string { + if len(sections) == 0 { + return "" + } + const truncationWidth = 1 // width of "…" + var ( s string next string maxWidth = windowWidth - stashViewHorizontalPadding - truncationWidth ) - if len(sections) == 0 { - return s - } for i := 0; i < len(sections); i++ { // If we need this more often we'll formalize something rather than @@ -731,6 +733,8 @@ func stashHelpViewBuilder(windowWidth int, sections ...string) string { next += stashHelpDivider } + // Only this (and the following) help text items if we have the + // horizontal space if ansi.PrintableRuneWidth(s)+ansi.PrintableRuneWidth(next) >= maxWidth { s += common.Subtle("…") break