mirror of
https://github.com/junegunn/fzf.git
synced 2025-05-19 04:40:22 -07:00
Fix {q} in preview window affected by 'search' action
This commit is contained in:
parent
01d9d9c8c8
commit
f975b40236
@ -638,6 +638,7 @@ type previewRequest struct {
|
||||
scrollOffset int
|
||||
list []*Item
|
||||
env []string
|
||||
query string
|
||||
}
|
||||
|
||||
type previewResult struct {
|
||||
@ -4385,6 +4386,7 @@ func (t *Terminal) Loop() error {
|
||||
var items []*Item
|
||||
var commandTemplate string
|
||||
var env []string
|
||||
var query string
|
||||
initialOffset := 0
|
||||
t.previewBox.Wait(func(events *util.Events) {
|
||||
for req, value := range *events {
|
||||
@ -4398,6 +4400,7 @@ func (t *Terminal) Loop() error {
|
||||
initialOffset = request.scrollOffset
|
||||
items = request.list
|
||||
env = request.env
|
||||
query = request.query
|
||||
}
|
||||
}
|
||||
events.Clear()
|
||||
@ -4411,8 +4414,7 @@ func (t *Terminal) Loop() error {
|
||||
version++
|
||||
// We don't display preview window if no match
|
||||
if items[0] != nil {
|
||||
_, query := t.Input()
|
||||
command, tempFiles := t.replacePlaceholder(commandTemplate, false, string(query), items)
|
||||
command, tempFiles := t.replacePlaceholder(commandTemplate, false, query, items)
|
||||
cmd := t.executor.ExecCommand(command, true)
|
||||
cmd.Env = env
|
||||
|
||||
@ -4540,7 +4542,7 @@ func (t *Terminal) Loop() error {
|
||||
if len(command) > 0 && t.canPreview() {
|
||||
_, list := t.buildPlusList(command, false)
|
||||
t.cancelPreview()
|
||||
t.previewBox.Set(reqPreviewEnqueue, previewRequest{command, t.evaluateScrollOffset(), list, t.environForPreview()})
|
||||
t.previewBox.Set(reqPreviewEnqueue, previewRequest{command, t.evaluateScrollOffset(), list, t.environForPreview(), string(t.input)})
|
||||
}
|
||||
}
|
||||
|
||||
@ -4972,7 +4974,7 @@ func (t *Terminal) Loop() error {
|
||||
if valid {
|
||||
t.cancelPreview()
|
||||
t.previewBox.Set(reqPreviewEnqueue,
|
||||
previewRequest{t.previewOpts.command, t.evaluateScrollOffset(), list, t.environForPreview()})
|
||||
previewRequest{t.previewOpts.command, t.evaluateScrollOffset(), list, t.environForPreview(), string(t.input)})
|
||||
}
|
||||
} else {
|
||||
// Discard the preview content so that it won't accidentally appear
|
||||
|
@ -544,4 +544,18 @@ class TestPreview < TestInteractive
|
||||
tmux.send_keys :Up
|
||||
tmux.until { |lines| assert_includes lines, '> 2' }
|
||||
end
|
||||
|
||||
def test_preview_query_should_not_be_affected_by_search
|
||||
tmux.send_keys "seq 1 | #{FZF} --bind 'change:transform-search(echo {q:1})' --preview 'echo [{q}/{}]'", :Enter
|
||||
tmux.until { |lines| assert_equal 1, lines.match_count }
|
||||
tmux.send_keys '1'
|
||||
tmux.until { |lines| assert lines.any_include?('[1/1]') }
|
||||
tmux.send_keys :Space
|
||||
tmux.until { |lines| assert lines.any_include?('[1 /1]') }
|
||||
tmux.send_keys '2'
|
||||
tmux.until do |lines|
|
||||
assert lines.any_include?('[1 2/1]')
|
||||
assert_equal 1, lines.match_count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user