diff options
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/github.com/jesseduffield/gocui/view.go | 46 | ||||
-rw-r--r-- | vendor/modules.txt | 2 |
2 files changed, 43 insertions, 5 deletions
diff --git a/vendor/github.com/jesseduffield/gocui/view.go b/vendor/github.com/jesseduffield/gocui/view.go index 3577c9ccf..d4a27f736 100644 --- a/vendor/github.com/jesseduffield/gocui/view.go +++ b/vendor/github.com/jesseduffield/gocui/view.go @@ -1265,14 +1265,52 @@ func lineWrap(line []cell, columns int) [][]cell { var n int var offset int + lastWhitespaceIndex := -1 lines := make([][]cell, 0, 1) for i := range line { - rw := runewidth.RuneWidth(line[i].chr) + currChr := line[i].chr + rw := runewidth.RuneWidth(currChr) n += rw + // if currChr == 'g' { + // panic(n) + // } if n > columns { - n = rw - lines = append(lines, line[offset:i]) - offset = i + // This code is convoluted but we've got comprehensive tests so feel free to do whatever you want + // to the code to simplify it so long as our tests still pass. + if currChr == ' ' { + // if the line ends in a space, we'll omit it. This means there'll be no + // way to distinguish between a clean break and a mid-word break, but + // I think it's worth it. + lines = append(lines, line[offset:i]) + offset = i + 1 + n = 0 + } else if currChr == '-' { + // if the last character is hyphen and the width of line is equal to the columns + lines = append(lines, line[offset:i]) + offset = i + n = rw + } else if lastWhitespaceIndex != -1 && lastWhitespaceIndex+1 != i { + // if there is a space in the line and the line is not breaking at a space/hyphen + if line[lastWhitespaceIndex].chr == '-' { + // if break occurs at hyphen, we'll retain the hyphen + lines = append(lines, line[offset:lastWhitespaceIndex+1]) + offset = lastWhitespaceIndex + 1 + n = i - offset + } else { + // if break occurs at space, we'll omit the space + lines = append(lines, line[offset:lastWhitespaceIndex]) + offset = lastWhitespaceIndex + 1 + n = i - offset + 1 + } + } else { + // in this case we're breaking mid-word + lines = append(lines, line[offset:i]) + offset = i + n = rw + } + lastWhitespaceIndex = -1 + } else if line[i].chr == ' ' || line[i].chr == '-' { + lastWhitespaceIndex = i } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 5aa0a325b..88efe8b86 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -172,7 +172,7 @@ github.com/jesseduffield/go-git/v5/utils/merkletrie/filesystem github.com/jesseduffield/go-git/v5/utils/merkletrie/index github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame github.com/jesseduffield/go-git/v5/utils/merkletrie/noder -# github.com/jesseduffield/gocui v0.3.1-0.20230719120401-398f4965241f +# github.com/jesseduffield/gocui v0.3.1-0.20230723014157-03e858e46144 ## explicit; go 1.12 github.com/jesseduffield/gocui # github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 |