Skip to content
Myr

Add replace-query action

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

replace-query action replaces the query string with the current selection. If the selection is too long, it will be truncated. If the line contains meta-characters of fzf search syntax, it is possible that the line is no longer included in the updated result. e.g. echo '!hello' | fzf --bind ctrl-v:replace-query Close #1137

authored by Junegunn Choi · committed by Junegunn Choi · parent 1e8e1d3 · Browse files · 4 files+18 added−0 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+18 added−0 removed

  • tests:+9 added−0 removed
  • other:+9 added−0 removed

4 files+18 added−0 removed

modified:man/man1/fzf.1+1 added
523 unmodified lines
524 \fBpreview-page-down\fR525 \fBpreview-page-up\fR526 \fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR)527 \fBprint-query\fR (print query and exit)528 \fBreplace-query\fR (replace query string with the current selection)529 \fBselect-all\fR530 \fBtoggle\fR (\fIright-click\fR)531 \fBtoggle-all\fR532 \fBtoggle+down\fR \fIctrl-i (tab)\fR
73 unmodified lines
modified:src/options.go+2 added
662 unmodified lines
663 case "accept":664 appendAction(actAccept)665 case "print-query":666 appendAction(actPrintQuery)667 case "replace-query":668 appendAction(actReplaceQuery)669 case "backward-char":670 appendAction(actBackwardChar)671 case "backward-delete-char":672 appendAction(actBackwardDeleteChar)
589 unmodified lines
modified:src/terminal.go+6 added
201 unmodified lines
202 actHalfPageDown203 actJump204 actJumpAccept205 actPrintQuery206 actReplaceQuery207 actToggleSort208 actTogglePreview209 actTogglePreviewWrap210 actPreviewUp
1357 unmodified lines
1568 t.cx--1569 }1570 case actPrintQuery:1571 req(reqPrintQuery)1572 case actReplaceQuery:1573 if t.cy < t.merger.Length() {1574 t.input = t.merger.Get(t.cy).item.text.ToRunes()1575 t.cx = len(t.input)1576 }1577 case actAbort:1578 req(reqQuit)1579 case actDeleteChar:1580 t.delChar()
302 unmodified lines
modified:test/test_go.rb+9 added
767 unmodified lines
768 tmux.send_keys 'print-my-query', 'C-j'769 assert_equal %w[print-my-query], readonce.split($INPUT_RECORD_SEPARATOR)770 end771772 def test_bind_replace_query773 tmux.send_keys "seq 1 1000 | #{fzf '--print-query --bind=ctrl-j:replace-query'}", :Enter774 tmux.send_keys '1'775 tmux.until { |lines| lines[-2].end_with? '272/1000' }776 tmux.send_keys 'C-k', 'C-j'777 tmux.until { |lines| lines[-2].end_with? '29/1000' }778 tmux.until { |lines| lines[-1].end_with? '> 10' }779 end780781 def test_long_line782 data = '.' * 256 * 1024783 File.open(tempname, 'w') do |f|784 f << data
980 unmodified lines