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