mirror of
https://github.com/junegunn/fzf
synced 2026-08-06 19:21:42 +00:00
Implement word wrapping in the list section
This commit is contained in:
+14
-1
@@ -249,7 +249,7 @@ func (chars *Chars) Prepend(prefix string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (chars *Chars) Lines(multiLine bool, maxLines int, wrapCols int, wrapSignWidth int, tabstop int) ([][]rune, bool) {
|
||||
func (chars *Chars) Lines(multiLine bool, maxLines int, wrapCols int, wrapSignWidth int, tabstop int, wrapWord bool) ([][]rune, bool) {
|
||||
text := make([]rune, chars.Length())
|
||||
copy(text, chars.ToRunes())
|
||||
|
||||
@@ -307,6 +307,19 @@ func (chars *Chars) Lines(multiLine bool, maxLines int, wrapCols int, wrapSignWi
|
||||
if overflowIdx == 0 {
|
||||
overflowIdx = 1
|
||||
}
|
||||
if wrapWord {
|
||||
// Find last space/tab at or before overflowIdx
|
||||
breakIdx := -1
|
||||
for k := overflowIdx; k > 0; k-- {
|
||||
if line[k-1] == ' ' || line[k-1] == '\t' {
|
||||
breakIdx = k
|
||||
break
|
||||
}
|
||||
}
|
||||
if breakIdx > 0 {
|
||||
overflowIdx = breakIdx
|
||||
}
|
||||
}
|
||||
if len(wrapped) >= maxLines {
|
||||
return wrapped, true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user