summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-08-05 16:14:34 +1000
committerGitHub <noreply@github.com>2023-08-05 16:14:34 +1000
commitaf3101c7f2b9a53c608fd22ffab759c42a88d0a1 (patch)
tree9913901f8205bbe3e41dd784815c751d4a397db9
parentab5875c78fcd7fc2f0cdbc867dc84ef4331a5de3 (diff)
parentec7e9f92283117eb0eeb7e4e16cd540f4e8cb2be (diff)
Fix confirmation view sizing (#2879)
-rw-r--r--pkg/gui/controllers/helpers/confirmation_helper.go42
1 files changed, 35 insertions, 7 deletions
diff --git a/pkg/gui/controllers/helpers/confirmation_helper.go b/pkg/gui/controllers/helpers/confirmation_helper.go
index fe18dd638..c920df39f 100644
--- a/pkg/gui/controllers/helpers/confirmation_helper.go
+++ b/pkg/gui/controllers/helpers/confirmation_helper.go
@@ -61,17 +61,45 @@ func (self *ConfirmationHelper) DeactivateConfirmationPrompt() {
self.clearConfirmationViewKeyBindings()
}
+// Temporary hack: we're just duplicating the logic in `gocui.lineWrap`
func getMessageHeight(wrap bool, message string, width int) int {
- lines := strings.Split(message, "\n")
+ if !wrap {
+ return len(strings.Split(message, "\n"))
+ }
+
lineCount := 0
- // if we need to wrap, calculate height to fit content within view's width
- if wrap {
- for _, line := range lines {
- lineCount += runewidth.StringWidth(line)/width + 1
+ lines := strings.Split(message, "\n")
+
+ for _, line := range lines {
+ n := 0
+ lastWhitespaceIndex := -1
+ for i, currChr := range line {
+ rw := runewidth.RuneWidth(currChr)
+ n += rw
+
+ if n > width {
+ if currChr == ' ' {
+ n = 0
+ } else if currChr == '-' {
+ n = rw
+ } else if lastWhitespaceIndex != -1 && lastWhitespaceIndex+1 != i {
+ if line[lastWhitespaceIndex] == '-' {
+ n = i - lastWhitespaceIndex
+ } else {
+ n = i - lastWhitespaceIndex + 1
+ }
+ } else {
+ n = rw
+ }
+ lineCount++
+ lastWhitespaceIndex = -1
+ } else if currChr == ' ' || currChr == '-' {
+ lastWhitespaceIndex = i
+ }
}
- } else {
- lineCount = len(lines)
+ lineCount++
}
+
return lineCount
}