diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index 89d7f93..0dfb77c 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -525,6 +525,7 @@ triggered whenever the query string is changed. \fBpreview-page-up\fR \fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR) \fBprint-query\fR (print query and exit) + \fBreplace-query\fR (replace query string with the current selection) \fBselect-all\fR \fBtoggle\fR (\fIright-click\fR) \fBtoggle-all\fR diff --git a/src/options.go b/src/options.go index 11a5021..730c116 100644 --- a/src/options.go +++ b/src/options.go @@ -664,6 +664,8 @@ func parseKeymap(keymap map[int][]action, str string) { appendAction(actAccept) case "print-query": appendAction(actPrintQuery) + case "replace-query": + appendAction(actReplaceQuery) case "backward-char": appendAction(actBackwardChar) case "backward-delete-char": diff --git a/src/terminal.go b/src/terminal.go index 2da2e4c..82f0ac9 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -203,6 +203,7 @@ const ( actJump actJumpAccept actPrintQuery + actReplaceQuery actToggleSort actTogglePreview actTogglePreviewWrap @@ -1568,6 +1569,11 @@ func (t *Terminal) Loop() { } case actPrintQuery: req(reqPrintQuery) + case actReplaceQuery: + if t.cy < t.merger.Length() { + t.input = t.merger.Get(t.cy).item.text.ToRunes() + t.cx = len(t.input) + } case actAbort: req(reqQuit) case actDeleteChar: diff --git a/test/test_go.rb b/test/test_go.rb index 111595e..eca458c 100644 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -769,6 +769,15 @@ class TestGoFZF < TestBase assert_equal %w[print-my-query], readonce.split($INPUT_RECORD_SEPARATOR) end + def test_bind_replace_query + tmux.send_keys "seq 1 1000 | #{fzf '--print-query --bind=ctrl-j:replace-query'}", :Enter + tmux.send_keys '1' + tmux.until { |lines| lines[-2].end_with? '272/1000' } + tmux.send_keys 'C-k', 'C-j' + tmux.until { |lines| lines[-2].end_with? '29/1000' } + tmux.until { |lines| lines[-1].end_with? '> 10' } + end + def test_long_line data = '.' * 256 * 1024 File.open(tempname, 'w') do |f|