Skip to content

Commit 86cf561

Browse files
committed
Fix off-by-one error when breaking lines at a hyphen
The test that we're adapting here shows what's wrong: we end up with a wrapped line that's one character longer than our allowed width.
1 parent 68c437b commit 86cf561

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

view.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ func lineWrap(line []cell, columns int) [][]cell {
15181518
// if break occurs at hyphen, we'll retain the hyphen
15191519
lines = append(lines, line[offset:lastWhitespaceIndex+1])
15201520
offset = lastWhitespaceIndex + 1
1521-
n = i - offset
1521+
n = i - offset + 1
15221522
} else {
15231523
// if break occurs at space, we'll omit the space
15241524
lines = append(lines, line[offset:lastWhitespaceIndex])

view_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ func TestLineWrap(t *testing.T) {
221221
expected: []string{
222222
"one-two-",
223223
"three-",
224-
"four-five",
224+
"four-",
225+
"five",
225226
},
226227
},
227228
{

0 commit comments

Comments
 (0)