Skip to content
Myr

Fix tab width when --frozen-left is used

Before adoption: this commit came in with the history the project adopted, so no landing records it.

https://github.com/junegunn/fzf/pull/4703#issuecomment-4004258816

authored by Junegunn Choi · committed by Junegunn Choi · parent 260d160 · Browse files · 2 files+24 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • https: //github.com/junegunn/fzf/pull/4703#issuecomment-4004258816

Diff stats

2 files+24 added−3 removed

  • tests:+10 added−0 removed
  • other:+14 added−3 removed

2 files+24 added−3 removed

modified:src/terminal.go+14 added-3 removed
3903 unmodified lines
3904 middle = line[splitOffsetLeft:splitOffsetRight]3905 frozenRight = line[splitOffsetRight:]3906 }3907 displayWidthSum := 03908 displayWidthLeft := 03909 todo := [3]func(){}3910 for fidx, runes := range [][]rune{frozenLeft, frozenRight, middle} {3911 if len(runes) == 0 {3912 continue
17 unmodified lines
3930 if fidx < 2 {3931 // For frozen parts, reserve space for the ellipsis in the middle part3932 adjustedMaxWidth -= ellipsisWidth3933 }3934 var prefixWidth int3935 if fidx == 2 {3936 prefixWidth = displayWidthLeft3937 }3933 displayWidth = t.displayWidthWithLimit(runes, 0, adjustedMaxWidth)3938 displayWidth = t.displayWidthWithLimit(runes, prefixWidth, adjustedMaxWidth)3939 if !t.wrap && displayWidth > adjustedMaxWidth {3940 maxe = util.Constrain(maxe+min(maxWidth/2-ellipsisWidth, t.hscrollOff), 0, len(runes))3941 transformOffsets := func(diff int32) {3942 for idx := range offs {
29 unmodified lines
3972 }3973 displayWidth = t.displayWidthWithLimit(runes, 0, maxWidth)3974 }3975 displayWidthSum += displayWidth3976 if fidx == 0 {3977 displayWidthLeft = displayWidth3978 }39793980 if maxWidth > 0 {3981 color := colBase3982 if hidden {3983 color = color.WithFg(t.theme.Nomatch)3984 }3985 todo[fidx] = func() {3978 t.printColoredString(t.window, runes, offs, color)3986 t.printColoredString(t.window, runes, offs, color, prefixWidth)3987 }3988 } else {3989 break3990 }
18 unmodified lines
40094010 return finalLineNum4011}40124005func (t *Terminal) printColoredString(window tui.Window, text []rune, offsets []colorOffset, colBase tui.ColorPair) {4013func (t *Terminal) printColoredString(window tui.Window, text []rune, offsets []colorOffset, colBase tui.ColorPair, initialPrefixWidth ...int) {4014 var index int324015 var substr string4016 var prefixWidth int4017 if len(initialPrefixWidth) > 0 {4018 prefixWidth = initialPrefixWidth[0]4019 }4020 maxOffset := int32(len(text))4021 var url *url4022 for _, offset := range offsets {4023 b := util.Constrain(offset.offset[0], index, maxOffset)
3787 unmodified lines
modified:test/test_core.rb+10 added
1188 unmodified lines
1189 tmux.send_keys :Space1190 tmux.until { |lines| assert lines.any_include?('9999␊10000') }1191 end11921193 def test_freeze_left_tabstop1194 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 space1198 # 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), :Enter1200 tmux.until { |lines| assert_equal '> 1 2 3', lines[-3] }1201 end12021203 def test_freeze_left_keep_right1204 tmux.send_keys %(seq 10000 | #{FZF} --read0 --delimiter "\n" --freeze-left 3 --keep-right --ellipsis XX --no-multi-line --bind space:toggle-multi-line), :Enter1205 tmux.until { |lines| assert_match(/^> 1␊2␊3XX.*10000␊$/, lines[-3]) }1206 tmux.send_keys '5'
1250 unmodified lines