summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-03-16 01:55:11 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-03-16 01:57:20 +0900
commitf92f9f137a7a222465892f30776db48a7ecc8ad9 (patch)
tree1995000c3dad6887ad931f3fb4bb6c9234c6477e /src/util
parent87f7f436e8e6de98336eb26d695bec93cc5b6b07 (diff)
downloadfzf-f92f9f137a7a222465892f30776db48a7ecc8ad9.tar.gz
Fix wrapping of the list section
# The first line of the second chunk would prematurely wrap printf '%0500s\n\n%0500s' 0 0 | fzf --wrap --read0
Diffstat (limited to 'src/util')
-rw-r--r--src/util/chars.go5
-rw-r--r--src/util/chars_test.go2
2 files changed, 5 insertions, 2 deletions
diff --git a/src/util/chars.go b/src/util/chars.go
index dd037caa..e5234303 100644
--- a/src/util/chars.go
+++ b/src/util/chars.go
@@ -294,9 +294,10 @@ func (chars *Chars) Lines(multiLine bool, maxLines int, wrapCols int, wrapSignWi
line = line[:len(line)-1]
}
+ hasWrapSign := false
for {
cols := wrapCols
- if len(wrapped) > 0 {
+ if hasWrapSign {
cols -= wrapSignWidth
}
_, overflowIdx := RunesWidth(line, 0, tabstop, cols)
@@ -309,9 +310,11 @@ func (chars *Chars) Lines(multiLine bool, maxLines int, wrapCols int, wrapSignWi
return wrapped, true
}
wrapped = append(wrapped, line[:overflowIdx])
+ hasWrapSign = true
line = line[overflowIdx:]
continue
}
+ hasWrapSign = false
// Restore trailing '\n'
if newline {
diff --git a/src/util/chars_test.go b/src/util/chars_test.go
index 0d3e4f37..c3d6c994 100644
--- a/src/util/chars_test.go
+++ b/src/util/chars_test.go
@@ -76,7 +76,7 @@ func TestCharsLines(t *testing.T) {
check(true, 100, 3, 1, 1, 8, false)
// With wrap sign (3 + 2)
- check(true, 100, 3, 2, 1, 12, false)
+ check(true, 100, 3, 2, 1, 10, false)
// With wrap sign (3 + 2) and no multi-line
check(false, 100, 3, 2, 1, 13, false)