Fix --preview-window follow not working correctly with wrapping

Fix #3243
Fix #4258
This commit is contained in:
Junegunn Choi
2026-02-18 21:36:23 +09:00
parent 69e9abdab4
commit c338df02c4
6 changed files with 98 additions and 8 deletions
+4 -2
View File
@@ -1423,8 +1423,10 @@ func (w *LightWindow) fill(str string, resetCode string) FillReturn {
for i, line := range allLines {
lines := WrapLine(line, w.posx, w.width, w.tabstop, w.wrapSignWidth)
for j, wl := range lines {
w.stderrInternal(wl.Text, false, resetCode)
w.posx += wl.DisplayWidth
if w.posx < w.width {
w.stderrInternal(wl.Text, false, resetCode)
w.posx += wl.DisplayWidth
}
// Wrap line
if j < len(lines)-1 || i < len(allLines)-1 {
+3 -1
View File
@@ -971,7 +971,9 @@ func (w *TcellWindow) fillString(text string, pair ColorPair) FillReturn {
w.renderWrapSign(style)
}
}
w.renderGraphemes(wl.Text, style)
if w.lastX < w.width {
w.renderGraphemes(wl.Text, style)
}
}
}
if w.lastX >= w.width {
+4 -3
View File
@@ -1377,7 +1377,8 @@ func WrapLine(input string, prefixLength int, initialMax int, tabstop int, wrapS
width := 0
line := ""
gr := uniseg.NewGraphemes(input)
max := initialMax
maxWidth := initialMax
contMax := max(1, initialMax-wrapSignWidth)
for gr.Next() {
rs := gr.Runes()
str := string(rs)
@@ -1392,14 +1393,14 @@ func WrapLine(input string, prefixLength int, initialMax int, tabstop int, wrapS
}
width += w
if prefixLength+width <= max {
if prefixLength+width <= maxWidth {
line += str
} else {
lines = append(lines, WrappedLine{string(line), width - w})
line = str
prefixLength = 0
width = w
max = initialMax - wrapSignWidth
maxWidth = contMax
}
}
lines = append(lines, WrappedLine{string(line), width})