File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
8282func (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
Original file line number Diff line number Diff 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" ,
You can’t perform that action at this time.
0 commit comments