mirror of
https://github.com/junegunn/fzf.git
synced 2026-03-07 15:42:28 +08:00
Fix tab width when --frozen-left is used
https://github.com/junegunn/fzf/pull/4703#issuecomment-4004258816
This commit is contained in:
@@ -3905,6 +3905,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
|
||||
frozenRight = line[splitOffsetRight:]
|
||||
}
|
||||
displayWidthSum := 0
|
||||
displayWidthLeft := 0
|
||||
todo := [3]func(){}
|
||||
for fidx, runes := range [][]rune{frozenLeft, frozenRight, middle} {
|
||||
if len(runes) == 0 {
|
||||
@@ -3930,7 +3931,11 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
|
||||
// For frozen parts, reserve space for the ellipsis in the middle part
|
||||
adjustedMaxWidth -= ellipsisWidth
|
||||
}
|
||||
displayWidth = t.displayWidthWithLimit(runes, 0, adjustedMaxWidth)
|
||||
var prefixWidth int
|
||||
if fidx == 2 {
|
||||
prefixWidth = displayWidthLeft
|
||||
}
|
||||
displayWidth = t.displayWidthWithLimit(runes, prefixWidth, adjustedMaxWidth)
|
||||
if !t.wrap && displayWidth > adjustedMaxWidth {
|
||||
maxe = util.Constrain(maxe+min(maxWidth/2-ellipsisWidth, t.hscrollOff), 0, len(runes))
|
||||
transformOffsets := func(diff int32) {
|
||||
@@ -3968,6 +3973,9 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
|
||||
displayWidth = t.displayWidthWithLimit(runes, 0, maxWidth)
|
||||
}
|
||||
displayWidthSum += displayWidth
|
||||
if fidx == 0 {
|
||||
displayWidthLeft = displayWidth
|
||||
}
|
||||
|
||||
if maxWidth > 0 {
|
||||
color := colBase
|
||||
@@ -3975,7 +3983,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
|
||||
color = color.WithFg(t.theme.Nomatch)
|
||||
}
|
||||
todo[fidx] = func() {
|
||||
t.printColoredString(t.window, runes, offs, color)
|
||||
t.printColoredString(t.window, runes, offs, color, prefixWidth)
|
||||
}
|
||||
} else {
|
||||
break
|
||||
@@ -4002,10 +4010,13 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat
|
||||
return finalLineNum
|
||||
}
|
||||
|
||||
func (t *Terminal) printColoredString(window tui.Window, text []rune, offsets []colorOffset, colBase tui.ColorPair) {
|
||||
func (t *Terminal) printColoredString(window tui.Window, text []rune, offsets []colorOffset, colBase tui.ColorPair, initialPrefixWidth ...int) {
|
||||
var index int32
|
||||
var substr string
|
||||
var prefixWidth int
|
||||
if len(initialPrefixWidth) > 0 {
|
||||
prefixWidth = initialPrefixWidth[0]
|
||||
}
|
||||
maxOffset := int32(len(text))
|
||||
var url *url
|
||||
for _, offset := range offsets {
|
||||
|
||||
@@ -1190,6 +1190,16 @@ class TestCore < TestInteractive
|
||||
tmux.until { |lines| assert lines.any_include?('9999␊10000') }
|
||||
end
|
||||
|
||||
def test_freeze_left_tabstop
|
||||
writelines(["1\t2\t3"])
|
||||
# With --freeze-left 1 and --tabstop=2:
|
||||
# Frozen left: "1" (width 1)
|
||||
# Middle starts with "\t" at prefix width 1, tabstop 2 → 1 space
|
||||
# Then "2" at column 2, next "\t" at column 3 → 1 space, then "3"
|
||||
tmux.send_keys %(cat #{tempname} | #{FZF} --tabstop=2 --freeze-left 1), :Enter
|
||||
tmux.until { |lines| assert_equal '> 1 2 3', lines[-3] }
|
||||
end
|
||||
|
||||
def test_freeze_left_keep_right
|
||||
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
|
||||
tmux.until { |lines| assert_match(/^> 1␊2␊3XX.*10000␊$/, lines[-3]) }
|
||||
|
||||
Reference in New Issue
Block a user