Fix truncation of colored line when --preview-window wrap is set

Fix #2346
This commit is contained in:
Junegunn Choi 2021-03-12 19:56:24 +09:00
parent 8ae94f0059
commit 7310370a31
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
2 changed files with 7 additions and 8 deletions

View File

@ -1320,8 +1320,9 @@ func (t *Terminal) renderPreviewText(unchanged bool) {
prefixWidth := 0
_, _, ansi = extractColor(line, ansi, func(str string, ansi *ansiState) bool {
trimmed := []rune(str)
trimmedLen := 0
if !t.previewOpts.wrap {
trimmed, _ = t.trimRight(trimmed, maxWidth-t.pwindow.X())
trimmed, trimmedLen = t.trimRight(trimmed, maxWidth-t.pwindow.X())
}
str, width := t.processTabs(trimmed, prefixWidth)
prefixWidth += width
@ -1331,7 +1332,8 @@ func (t *Terminal) renderPreviewText(unchanged bool) {
} else {
fillRet = t.pwindow.CFill(tui.ColPreview.Fg(), tui.ColPreview.Bg(), tui.AttrRegular, str)
}
return fillRet == tui.FillContinue || t.previewOpts.wrap && fillRet == tui.FillNextLine
return trimmedLen == 0 &&
(fillRet == tui.FillContinue || t.previewOpts.wrap && fillRet == tui.FillNextLine)
})
t.previewer.scrollable = t.previewer.scrollable || t.pwindow.Y() == height-1 && t.pwindow.X() == t.pwindow.Width()
if fillRet == tui.FillNextLine {

View File

@ -906,12 +906,6 @@ func (w *LightWindow) fill(str string, onMove func()) FillReturn {
for i, line := range allLines {
lines := wrapLine(line, w.posx, w.width, w.tabstop)
for j, wl := range lines {
if w.posx >= w.Width()-1 && wl.displayWidth == 0 {
if w.posy < w.height-1 {
w.Move(w.posy+1, 0)
}
return FillNextLine
}
w.stderrInternal(wl.text, false)
w.posx += wl.displayWidth
@ -926,6 +920,9 @@ func (w *LightWindow) fill(str string, onMove func()) FillReturn {
}
}
}
if w.posx >= w.Width()-1 {
return FillNextLine
}
return FillContinue
}