Skip to content

Commit

Permalink
Truncate wrap signs in extremely narrow preview window
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Feb 11, 2025
1 parent 282884a commit 66ca16f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/tui/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,9 +1159,16 @@ func (w *LightWindow) fill(str string, resetCode string) FillReturn {
w.Move(w.posy+1, 0)
w.renderer.stderr(resetCode)
if len(lines) > 1 {
w.stderrInternal(DIM+w.wrapSign, false, resetCode)
sign := w.wrapSign
width := w.wrapSignWidth
if width > w.width-w.posx {
runes, truncatedWidth := util.Truncate(w.wrapSign, w.width-w.posx)
sign = string(runes)
width = truncatedWidth
}
w.stderrInternal(DIM+sign, false, resetCode)
w.renderer.stderr(resetCode)
w.Move(w.posy, w.wrapSignWidth)
w.Move(w.posy, width)
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/tui/tcell.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,18 @@ Loop:
xPos := w.left + w.lastX + lx
if xPos >= w.left+w.width {
w.lastY++
if w.lastY >= w.height {
return FillSuspend
}
w.lastX = 0
lx = 0
xPos = w.left
wgr := uniseg.NewGraphemes(w.wrapSign)
sign := w.wrapSign
if w.wrapSignWidth > w.width {
runes, _ := util.Truncate(sign, w.width)
sign = string(runes)
}
wgr := uniseg.NewGraphemes(sign)
for wgr.Next() {
rs := wgr.Runes()
_screen.SetContent(w.left+lx, w.top+w.lastY, rs[0], rs[1:], style.Dim(true))
Expand Down

0 comments on commit 66ca16f

Please sign in to comment.