Skip to content

Commit e7300fe

Browse files
committed
Fix tab width when --frozen-left is used
#4703 (comment)
1 parent 260d160 commit e7300fe

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

src/terminal.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3905,6 +3905,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
39053905
frozenRight = line[splitOffsetRight:]
39063906
}
39073907
displayWidthSum := 0
3908+
displayWidthLeft := 0
39083909
todo := [3]func(){}
39093910
for fidx, runes := range [][]rune{frozenLeft, frozenRight, middle} {
39103911
if len(runes) == 0 {
@@ -3930,7 +3931,11 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
39303931
// For frozen parts, reserve space for the ellipsis in the middle part
39313932
adjustedMaxWidth -= ellipsisWidth
39323933
}
3933-
displayWidth = t.displayWidthWithLimit(runes, 0, adjustedMaxWidth)
3934+
var prefixWidth int
3935+
if fidx == 2 {
3936+
prefixWidth = displayWidthLeft
3937+
}
3938+
displayWidth = t.displayWidthWithLimit(runes, prefixWidth, adjustedMaxWidth)
39343939
if !t.wrap && displayWidth > adjustedMaxWidth {
39353940
maxe = util.Constrain(maxe+min(maxWidth/2-ellipsisWidth, t.hscrollOff), 0, len(runes))
39363941
transformOffsets := func(diff int32) {
@@ -3968,14 +3973,17 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
39683973
displayWidth = t.displayWidthWithLimit(runes, 0, maxWidth)
39693974
}
39703975
displayWidthSum += displayWidth
3976+
if fidx == 0 {
3977+
displayWidthLeft = displayWidth
3978+
}
39713979

39723980
if maxWidth > 0 {
39733981
color := colBase
39743982
if hidden {
39753983
color = color.WithFg(t.theme.Nomatch)
39763984
}
39773985
todo[fidx] = func() {
3978-
t.printColoredString(t.window, runes, offs, color)
3986+
t.printColoredString(t.window, runes, offs, color, prefixWidth)
39793987
}
39803988
} else {
39813989
break
@@ -4002,10 +4010,13 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
40024010
return finalLineNum
40034011
}
40044012

4005-
func (t *Terminal) printColoredString(window tui.Window, text []rune, offsets []colorOffset, colBase tui.ColorPair) {
4013+
func (t *Terminal) printColoredString(window tui.Window, text []rune, offsets []colorOffset, colBase tui.ColorPair, initialPrefixWidth ...int) {
40064014
var index int32
40074015
var substr string
40084016
var prefixWidth int
4017+
if len(initialPrefixWidth) > 0 {
4018+
prefixWidth = initialPrefixWidth[0]
4019+
}
40094020
maxOffset := int32(len(text))
40104021
var url *url
40114022
for _, offset := range offsets {

test/test_core.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,16 @@ def test_keep_right
11901190
tmux.until { |lines| assert lines.any_include?('9999␊10000') }
11911191
end
11921192

1193+
def test_freeze_left_tabstop
1194+
writelines(["1\t2\t3"])
1195+
# With --freeze-left 1 and --tabstop=2:
1196+
# Frozen left: "1" (width 1)
1197+
# Middle starts with "\t" at prefix width 1, tabstop 2 → 1 space
1198+
# Then "2" at column 2, next "\t" at column 3 → 1 space, then "3"
1199+
tmux.send_keys %(cat #{tempname} | #{FZF} --tabstop=2 --freeze-left 1), :Enter
1200+
tmux.until { |lines| assert_equal '> 1 2 3', lines[-3] }
1201+
end
1202+
11931203
def test_freeze_left_keep_right
11941204
tmux.send_keys %(seq 10000 | #{FZF} --read0 --delimiter "\n" --freeze-left 3 --keep-right --ellipsis XX --no-multi-line --bind space:toggle-multi-line), :Enter
11951205
tmux.until { |lines| assert_match(/^> 1␊2␊3XX.*10000␊$/, lines[-3]) }

0 commit comments

Comments
 (0)