Compare commits

..

2 Commits

Author SHA1 Message Date
Junegunn Choi
5546c65491 Fix rendering of items with tabs when using a non-default ellipsis
Fix #4505
2025-08-27 23:31:31 +09:00
junegunn
f2179f015c Deploying to master from @ junegunn/fzf@9a53d84b9c 🚀 2025-08-24 00:02:30 +00:00
3 changed files with 15 additions and 15 deletions

File diff suppressed because one or more lines are too long

View File

@@ -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)

View File

@@ -873,13 +873,13 @@ func init() {
Current: ColorAttr{colYellow, AttrUndefined}, Current: ColorAttr{colYellow, AttrUndefined},
CurrentMatch: ColorAttr{colGreen, AttrUndefined}, CurrentMatch: ColorAttr{colGreen, AttrUndefined},
Spinner: ColorAttr{colGreen, AttrUndefined}, Spinner: ColorAttr{colGreen, AttrUndefined},
Info: ColorAttr{colDefault, Italic}, Info: ColorAttr{colWhite, AttrUndefined},
Cursor: ColorAttr{colRed, AttrUndefined}, Cursor: ColorAttr{colRed, AttrUndefined},
Marker: ColorAttr{colMagenta, AttrUndefined}, Marker: ColorAttr{colMagenta, AttrUndefined},
Header: ColorAttr{colCyan, AttrUndefined}, Header: ColorAttr{colCyan, AttrUndefined},
Footer: ColorAttr{colCyan, AttrUndefined}, Footer: ColorAttr{colCyan, AttrUndefined},
Border: ColorAttr{colDefault, Dim}, Border: ColorAttr{colBlack, AttrUndefined},
BorderLabel: ColorAttr{colDefault, AttrUndefined}, BorderLabel: ColorAttr{colWhite, AttrUndefined},
Ghost: ColorAttr{colUndefined, Dim}, Ghost: ColorAttr{colUndefined, Dim},
Disabled: ColorAttr{colUndefined, AttrUndefined}, Disabled: ColorAttr{colUndefined, AttrUndefined},
PreviewFg: ColorAttr{colUndefined, AttrUndefined}, PreviewFg: ColorAttr{colUndefined, AttrUndefined},
@@ -921,7 +921,7 @@ func init() {
Current: ColorAttr{254, AttrUndefined}, Current: ColorAttr{254, AttrUndefined},
CurrentMatch: ColorAttr{151, AttrUndefined}, CurrentMatch: ColorAttr{151, AttrUndefined},
Spinner: ColorAttr{148, AttrUndefined}, Spinner: ColorAttr{148, AttrUndefined},
Info: ColorAttr{144, Italic}, Info: ColorAttr{144, AttrUndefined},
Cursor: ColorAttr{161, AttrUndefined}, Cursor: ColorAttr{161, AttrUndefined},
Marker: ColorAttr{168, AttrUndefined}, Marker: ColorAttr{168, AttrUndefined},
Header: ColorAttr{109, AttrUndefined}, Header: ColorAttr{109, AttrUndefined},
@@ -969,7 +969,7 @@ func init() {
Current: ColorAttr{237, AttrUndefined}, Current: ColorAttr{237, AttrUndefined},
CurrentMatch: ColorAttr{23, AttrUndefined}, CurrentMatch: ColorAttr{23, AttrUndefined},
Spinner: ColorAttr{65, AttrUndefined}, Spinner: ColorAttr{65, AttrUndefined},
Info: ColorAttr{101, Italic}, Info: ColorAttr{101, AttrUndefined},
Cursor: ColorAttr{161, AttrUndefined}, Cursor: ColorAttr{161, AttrUndefined},
Marker: ColorAttr{168, AttrUndefined}, Marker: ColorAttr{168, AttrUndefined},
Header: ColorAttr{31, AttrUndefined}, Header: ColorAttr{31, AttrUndefined},