1
1
mirror of https://github.com/walles/moar.git synced 2024-10-26 13:00:40 +03:00

Don't lose whitespace-only lines

This commit is contained in:
Johan Walles 2021-05-25 17:18:18 +02:00
parent a062dd25f8
commit 3dd20e609d
2 changed files with 8 additions and 5 deletions

View File

@ -48,14 +48,14 @@ func getWrapWidth(line []twin.Cell, maxWrapWidth int) int {
}
func wrapLine(width int, line []twin.Cell) [][]twin.Cell {
if len(line) == 0 {
return [][]twin.Cell{{}}
}
// Trailing space risks showing up by itself on a line, which would just
// look weird.
line = twin.TrimSpaceRight(line)
if len(line) == 0 {
return [][]twin.Cell{{}}
}
wrapped := make([][]twin.Cell, 0, len(line)/width)
for len(line) > width {
wrapWidth := getWrapWidth(line, width)

View File

@ -50,7 +50,10 @@ func TestEnoughRoomNoWrapping(t *testing.T) {
assertWrap(t, "This is a test", 20, "This is a test")
}
func TestWrapEmpty(t *testing.T) {
func TestWrapBlank(t *testing.T) {
assertWrap(t, " ", 4, "")
assertWrap(t, " ", 2, "")
assertWrap(t, "", 20, "")
}