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:
parent
a062dd25f8
commit
3dd20e609d
@ -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)
|
||||
|
@ -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, "")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user