Skip to content
Myr

Fix {q} in preview window affected by 'search' action

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

authored by Junegunn Choi · committed by Junegunn Choi · parent 01d9d9c · Browse files · 2 files+20 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

2 files+20 added−4 removed

  • tests:+14 added−0 removed
  • other:+6 added−4 removed

2 files+20 added−4 removed

modified:src/terminal.go+6 added-4 removed
636 unmodified lines
637 template string638 scrollOffset int639 list []*Item640 env []string641 query string642}643644type previewResult struct {645 version int64
3739 unmodified lines
4385 for {4386 var items []*Item4387 var commandTemplate string4388 var env []string4389 var query string4390 initialOffset := 04391 t.previewBox.Wait(func(events *util.Events) {4392 for req, value := range *events {4393 switch req {
5 unmodified lines
4399 commandTemplate = request.template4400 initialOffset = request.scrollOffset4401 items = request.list4402 env = request.env4403 query = request.query4404 }4405 }4406 events.Clear()4407 })
5 unmodified lines
4413 }4414 version++4415 // We don't display preview window if no match4416 if items[0] != nil {4414 _, query := t.Input()4415 command, tempFiles := t.replacePlaceholder(commandTemplate, false, string(query), items)4417 command, tempFiles := t.replacePlaceholder(commandTemplate, false, query, items)4418 cmd := t.executor.ExecCommand(command, true)4419 cmd.Env = env44204421 out, _ := cmd.StdoutPipe()
119 unmodified lines
4541 refreshPreview := func(command string) {4542 if len(command) > 0 && t.canPreview() {4543 _, list := t.buildPlusList(command, false)4544 t.cancelPreview()4543 t.previewBox.Set(reqPreviewEnqueue, previewRequest{command, t.evaluateScrollOffset(), list, t.environForPreview()})4545 t.previewBox.Set(reqPreviewEnqueue, previewRequest{command, t.evaluateScrollOffset(), list, t.environForPreview(), string(t.input)})4546 }4547 }45484549 go func() { // Render loop
423 unmodified lines
4973 valid, list := t.buildPlusList(t.previewOpts.command, false)4974 if valid {4975 t.cancelPreview()4976 t.previewBox.Set(reqPreviewEnqueue,4975 previewRequest{t.previewOpts.command, t.evaluateScrollOffset(), list, t.environForPreview()})4977 previewRequest{t.previewOpts.command, t.evaluateScrollOffset(), list, t.environForPreview(), string(t.input)})4978 }4979 } else {4980 // Discard the preview content so that it won't accidentally appear4981 // when preview window is re-enabled and previewDelay is triggered
1306 unmodified lines
modified:test/test_preview.rb+14 added
542 unmodified lines
543 tmux.until { |lines| assert_includes lines, '> 1' }544 tmux.send_keys :Up545 tmux.until { |lines| assert_includes lines, '> 2' }546 end547548 def test_preview_query_should_not_be_affected_by_search549 tmux.send_keys "seq 1 | #{FZF} --bind 'change:transform-search(echo {q:1})' --preview 'echo [{q}/{}]'", :Enter550 tmux.until { |lines| assert_equal 1, lines.match_count }551 tmux.send_keys '1'552 tmux.until { |lines| assert lines.any_include?('[1/1]') }553 tmux.send_keys :Space554 tmux.until { |lines| assert lines.any_include?('[1 /1]') }555 tmux.send_keys '2'556 tmux.until do |lines|557 assert lines.any_include?('[1 2/1]')558 assert_equal 1, lines.match_count559 end560 end561end