From 3dd20e609d475df5ff41f11caa202fb045baa807 Mon Sep 17 00:00:00 2001 From: Johan Walles Date: Tue, 25 May 2021 17:18:18 +0200 Subject: [PATCH] Don't lose whitespace-only lines --- m/linewrapper.go | 8 ++++---- m/linewrapper_test.go | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/m/linewrapper.go b/m/linewrapper.go index 4a61cbf..e28b6a2 100644 --- a/m/linewrapper.go +++ b/m/linewrapper.go @@ -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) diff --git a/m/linewrapper_test.go b/m/linewrapper_test.go index 75595d3..d183882 100644 --- a/m/linewrapper_test.go +++ b/m/linewrapper_test.go @@ -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, "") }