mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-17 07:43:39 -05:00
Fix rendering of items with tabs when using a non-default ellipsis
Fix #4505
This commit is contained in:
@@ -2617,11 +2617,11 @@ func (t *Terminal) updatePromptOffset() ([]rune, []rune) {
|
|||||||
}
|
}
|
||||||
maxWidth := util.Max(1, w.Width()-t.promptLen-1)
|
maxWidth := util.Max(1, w.Width()-t.promptLen-1)
|
||||||
|
|
||||||
_, overflow := t.trimLeft(t.input[:t.cx], maxWidth)
|
_, overflow := t.trimLeft(t.input[:t.cx], maxWidth, 0)
|
||||||
minOffset := int(overflow)
|
minOffset := int(overflow)
|
||||||
maxOffset := minOffset + (maxWidth-util.Max(0, maxWidth-t.cx))/2
|
maxOffset := minOffset + (maxWidth-util.Max(0, maxWidth-t.cx))/2
|
||||||
t.xoffset = util.Constrain(t.xoffset, minOffset, maxOffset)
|
t.xoffset = util.Constrain(t.xoffset, minOffset, maxOffset)
|
||||||
before, _ := t.trimLeft(t.input[t.xoffset:t.cx], maxWidth)
|
before, _ := t.trimLeft(t.input[t.xoffset:t.cx], maxWidth, 0)
|
||||||
beforeLen := t.displayWidth(before)
|
beforeLen := t.displayWidth(before)
|
||||||
after, _ := t.trimRight(t.input[t.cx:], maxWidth-beforeLen)
|
after, _ := t.trimRight(t.input[t.cx:], maxWidth-beforeLen)
|
||||||
afterLen := t.displayWidth(after)
|
afterLen := t.displayWidth(after)
|
||||||
@@ -3322,22 +3322,22 @@ func (t *Terminal) displayWidthWithLimit(runes []rune, prefixWidth int, limit in
|
|||||||
return width
|
return width
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) trimLeft(runes []rune, width int) ([]rune, int32) {
|
func (t *Terminal) trimLeft(runes []rune, width int, ellipsisWidth int) ([]rune, int32) {
|
||||||
width = util.Max(0, width)
|
width = util.Max(0, width)
|
||||||
var trimmed int32
|
var trimmed int32
|
||||||
// Assume that each rune takes at least one column on screen
|
// Assume that each rune takes at least one column on screen
|
||||||
if len(runes) > width+2 {
|
if len(runes) > width {
|
||||||
diff := len(runes) - width - 2
|
diff := len(runes) - width
|
||||||
trimmed = int32(diff)
|
trimmed = int32(diff)
|
||||||
runes = runes[diff:]
|
runes = runes[diff:]
|
||||||
}
|
}
|
||||||
|
|
||||||
currentWidth := t.displayWidth(runes)
|
currentWidth := t.displayWidth(runes)
|
||||||
|
|
||||||
for currentWidth > width && len(runes) > 0 {
|
for currentWidth > width-ellipsisWidth && len(runes) > 0 {
|
||||||
runes = runes[1:]
|
runes = runes[1:]
|
||||||
trimmed++
|
trimmed++
|
||||||
currentWidth = t.displayWidthWithLimit(runes, 2, width)
|
currentWidth = t.displayWidthWithLimit(runes, ellipsisWidth, width)
|
||||||
}
|
}
|
||||||
return runes, trimmed
|
return runes, trimmed
|
||||||
}
|
}
|
||||||
@@ -3562,7 +3562,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
|
|||||||
}
|
}
|
||||||
if t.hscroll {
|
if t.hscroll {
|
||||||
if t.keepRight && pos == nil {
|
if t.keepRight && pos == nil {
|
||||||
trimmed, diff := t.trimLeft(line, maxWidth-ellipsisWidth)
|
trimmed, diff := t.trimLeft(line, maxWidth, ellipsisWidth)
|
||||||
transformOffsets(diff, false)
|
transformOffsets(diff, false)
|
||||||
line = append(ellipsis, trimmed...)
|
line = append(ellipsis, trimmed...)
|
||||||
} else if !t.overflow(line[:maxe], maxWidth-ellipsisWidth) {
|
} else if !t.overflow(line[:maxe], maxWidth-ellipsisWidth) {
|
||||||
@@ -3578,7 +3578,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
|
|||||||
}
|
}
|
||||||
// ..ri..
|
// ..ri..
|
||||||
var diff int32
|
var diff int32
|
||||||
line, diff = t.trimLeft(line, maxWidth-ellipsisWidth)
|
line, diff = t.trimLeft(line, maxWidth, ellipsisWidth)
|
||||||
|
|
||||||
// Transform offsets
|
// Transform offsets
|
||||||
transformOffsets(diff, rightTrim)
|
transformOffsets(diff, rightTrim)
|
||||||
|
|||||||
Reference in New Issue
Block a user