Skip to content
Myr

Make --accept-nth compatible with --select-1

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

Fix #4287

authored by Junegunn Choi · committed by Junegunn Choi · parent bb64d84 · Browse files · 4 files+22 added−4 removed
This commit

State

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

Diff stats

4 files+22 added−4 removed

  • tests:+5 added−0 removed
  • other:+17 added−4 removed

4 files+22 added−4 removed

modified:src/core.go+10 added-1 removed
474 unmodified lines
475 }476 if len(opts.Expect) > 0 {477 opts.Printer("")478 }479 transformer := func(item *Item) string {480 return item.AsString(opts.Ansi)481 }482 if opts.AcceptNth != nil {483 fn := opts.AcceptNth(opts.Delimiter)484 transformer = func(item *Item) string {485 return item.acceptNth(opts.Ansi, opts.Delimiter, fn)486 }487 }488 for i := 0; i < count; i++ {480 opts.Printer(val.Get(i).item.AsString(opts.Ansi))489 opts.Printer(transformer(val.Get(i).item))490 }491 if count == 0 {492 exitCode = ExitNoMatch493 }
24 unmodified lines
modified:src/item.go+6 added
49 unmodified lines
50 return string(*item.origText)51 }52 return item.text.ToString()53}5455func (item *Item) acceptNth(stripAnsi bool, delimiter Delimiter, transformer func([]Token, int32) string) string {56 tokens := Tokenize(item.AsString(stripAnsi), delimiter)57 transformed := transformer(tokens, item.Index())58 return StripLastDelimiter(transformed, delimiter)59}
modified:src/terminal.go+1 added-3 removed
1573 unmodified lines
1574 return item.AsString(t.ansi)1575 }1576 if t.acceptNth != nil {1577 transform = func(item *Item) string {1578 tokens := Tokenize(item.AsString(t.ansi), t.delimiter)1579 transformed := t.acceptNth(tokens, item.Index())1580 return StripLastDelimiter(transformed, t.delimiter)1578 return item.acceptNth(t.ansi, t.delimiter, t.acceptNth)1579 }1580 }1581 found := len(t.selected) > 01582 if !found {
4711 unmodified lines
modified:test/test_core.rb+5 added
236 unmodified lines
237 tmux.send_keys "seq 1 100 | #{fzf(:with_nth, '..,..', :print_query, :q, 5555, :'1')}", :Enter238 assert_equal %w[5555 55], fzf_output_lines239 end240241 def test_select_1_accept_nth242 tmux.send_keys "seq 1 100 | #{fzf(:with_nth, '..,..', :print_query, :q, 5555, :'1', :accept_nth, '"{1} // {1}"')}", :Enter243 assert_equal ['5555', '55 // 55'], fzf_output_lines244 end245246 def test_exit_0247 tmux.send_keys "seq 1 100 | #{fzf(:with_nth, '..,..', :print_query, :q, 555_555, :'0')}", :Enter248 assert_equal %w[555555], fzf_output_lines249 end
1567 unmodified lines