Skip to content

Commit 949d0ca

Browse files
authored
Merge pull request #1155 from VXNCXNX/fix/wordwrap-long-word-row
fix: a word longer than the screen advances the wrap row by one
2 parents 072af71 + 6b98d2d commit 949d0ca

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

oviewer/convert_wordwrap.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ func (c *wordwrapConverter) convertWordWrap(src contents) contents {
8080

8181
// processWord handles the placement of a word in the output.
8282
func (proc *wordWrapProcessor) processWord(srcWord contents) {
83-
// Word is longer than screen width, add as-is and move to next line.
83+
// Word is longer than screen width, add as-is and move to the row it ends on.
84+
// The word can span several rows, so the row is recalculated from the output length
85+
// instead of being incremented by one.
8486
if len(srcWord) > proc.screenWidth {
8587
proc.dst = append(proc.dst, srcWord...)
86-
proc.row++
88+
proc.row = (len(proc.dst) / proc.screenWidth) + 1
8789
return
8890
}
8991

oviewer/convert_wordwrap_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ func TestConvertWordwrap(t *testing.T) {
9696
tabWidth: 4,
9797
wantStr: "01234567890123456789",
9898
},
99+
{
100+
name: "long word spanning multiple rows followed by a word",
101+
screenWidth: 5,
102+
str: "abcdefghijklmn op",
103+
tabWidth: 4,
104+
wantStr: "abcdefghijklmn op",
105+
},
106+
{
107+
name: "long word spanning multiple rows then wrap to a new row",
108+
screenWidth: 10,
109+
str: "aa bbbbbbbbbbbbbbbbbbbbbbbbb cc",
110+
tabWidth: 4,
111+
wantStr: "aa bbbbbbbbbbbbbbbbbbbbbbbbb cc",
112+
},
99113
{
100114
name: "escape sequence",
101115
str: "abc\x1b[31mdef\x1b[0mghi",

0 commit comments

Comments
 (0)