Skip to content

Commit

Permalink
Fix 'jump' when pointer is empty
Browse files Browse the repository at this point in the history
Fix #4270
  • Loading branch information
junegunn committed Feb 22, 2025
1 parent 77568e1 commit d79902a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2755,11 +2755,15 @@ func (t *Terminal) printItem(result Result, line int, maxLine int, index int, cu
item := result.item
_, selected := t.selected[item.Index()]
label := ""
extraWidth := 0
if t.jumping != jumpDisabled {
if index < len(t.jumpLabels) {
// Striped
current = index%2 == 0
label = t.jumpLabels[index:index+1] + strings.Repeat(" ", t.pointerLen-1)
label = t.jumpLabels[index:index+1] + strings.Repeat(" ", util.Max(0, t.pointerLen-1))
if t.pointerLen == 0 {
extraWidth = 1
}
}
} else if current {
label = t.pointer
Expand Down Expand Up @@ -2788,6 +2792,7 @@ func (t *Terminal) printItem(result Result, line int, maxLine int, index int, cu

maxWidth := t.window.Width() - (t.pointerLen + t.markerLen + 1)
postTask := func(lineNum int, width int, wrapped bool, forceRedraw bool) {
width += extraWidth
if (current || selected) && t.highlightLine {
color := tui.ColSelected
if current {
Expand Down
18 changes: 18 additions & 0 deletions test/test_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,24 @@ def test_jump_events
tmux.until { |lines| assert(lines.any? { it.include?('jump cancelled at 3') }) }
end

def test_jump_no_pointer
tmux.send_keys "seq 100 | #{FZF} --pointer= --jump-labels 12345 --bind ctrl-j:jump", :Enter
tmux.until { |lines| assert_equal 100, lines.match_count }
tmux.send_keys 'C-j'
tmux.until { |lines| assert_equal '5 5', lines[-7] }
tmux.send_keys 'C-c'
tmux.until { |lines| assert_equal ' 5', lines[-7] }
end

def test_jump_no_pointer_no_marker
tmux.send_keys "seq 100 | #{FZF} --pointer= --marker= --jump-labels 12345 --bind ctrl-j:jump", :Enter
tmux.until { |lines| assert_equal 100, lines.match_count }
tmux.send_keys 'C-j'
tmux.until { |lines| assert_equal '55', lines[-7] }
tmux.send_keys 'C-c'
tmux.until { |lines| assert_equal '5', lines[-7] }
end

def test_pointer
tmux.send_keys "seq 10 | #{fzf("--pointer '>>'")}", :Enter
# Assert that specified pointer is displayed
Expand Down

0 comments on commit d79902a

Please sign in to comment.