Skip to content

Commit

Permalink
Fix confirmation view sizing (#2879)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Aug 5, 2023
2 parents ab5875c + ec7e9f9 commit af3101c
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions pkg/gui/controllers/helpers/confirmation_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit af3101c

Please sign in to comment.