Add pos(...) action to move the cursor to the numeric position
Before adoption: this commit came in with the history the project adopted, so no landing records it.
# Put the cursor on the 10th item seq 100 | fzf --sync --bind 'start:pos(10)' # Put the cursor on the 10th to last item seq 100 | fzf --sync --bind 'start:pos(-10)' Close #3069 Close #395
authored by Junegunn Choi · committed by Junegunn Choi · parent d42e708 · Browse files · 5 files·+41 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+41 added−3 removed
- tests:+15 added−0 removed
- other:+26 added−3 removed
Provenance
- Commit
12af069- Tree
887acd1- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
d42e708
5 files changed+41 added−3 removed
modified:man/man1/fzf.1+3 added-2 removed
977 unmodified lines978 \fBenable-search\fR (enable search functionality)979 \fBend-of-line\fR \fIctrl-e end\fR980 \fBexecute(...)\fR (see below for the details)981 \fBexecute-silent(...)\fR (see below for the details)982- \fBfirst\fR (move to the first match)982+ \fBfirst\fR (move to the first match; same as \fBpos(1)\fR)983 \fBforward-char\fR \fIctrl-f right\fR984 \fBforward-word\fR \fIalt-f shift-right\fR985 \fBignore\fR986 \fBjump\fR (EasyMotion-like 2-keystroke movement)987 \fBjump-accept\fR (jump and accept)988 \fBkill-line\fR989 \fBkill-word\fR \fIalt-d\fR990- \fBlast\fR (move to the last match)990+ \fBlast\fR (move to the last match; same as \fBpos(-1)\fR)991 \fBnext-history\fR (\fIctrl-n\fR on \fB--history\fR)992 \fBnext-selected\fR (move to the next selected item)993 \fBpage-down\fR \fIpgdn\fR994 \fBpage-up\fR \fIpgup\fR995 \fBhalf-page-down\fR996 \fBhalf-page-up\fR997+ \fBpos(...)\fR (move cursor to the numeric position; negative number to count from the end)998 \fBprev-history\fR (\fIctrl-p\fR on \fB--history\fR)999 \fBprev-selected\fR (move to the previous selected item)1000 \fBpreview(...)\fR (see below for the details)1001 \fBpreview-down\fR \fIshift-down\fR165 unmodified linesmodified:src/options.go+3 added-1 removed
888 unmodified lines889 )890 891 func init() {892 executeRegexp = regexp.MustCompile(893- `(?si)[:+](execute(?:-multi|-silent)?|reload|preview|change-query|change-prompt|change-preview-window|change-preview|(?:re|un)bind)`)893+ `(?si)[:+](execute(?:-multi|-silent)?|reload|preview|change-query|change-prompt|change-preview-window|change-preview|(?:re|un)bind|pos)`)894 splitRegexp = regexp.MustCompile("[,:]+")895 actionNameRegexp = regexp.MustCompile("(?i)^[a-z-]+")896 }897 298 unmodified lines1196 case "change-prompt":1197 return actChangePrompt1198 case "change-query":1199 return actChangeQuery1200+ case "pos":1201+ return actPosition1202 case "execute":1203 return actExecute1204 case "execute-silent":1205 return actExecuteSilent767 unmodified linesmodified:src/terminal.go+11 added
295 unmodified lines296 actDown297 actUp298 actPageUp299 actPageDown300+ actPosition301 actHalfPageUp302 actHalfPageDown303 actJump304 actJumpAccept2532 unmodified lines2837 req(reqList)2838 case actLast:2839 t.vset(t.merger.Length() - 1)2840 req(reqList)2841+ case actPosition:2842+ if n, e := strconv.Atoi(a.a); e == nil {2843+ if n > 0 {2844+ n--2845+ } else if n < 0 {2846+ n += t.merger.Length()2847+ }2848+ t.vset(n)2849+ req(reqList)2850+ }2851 case actUnixLineDiscard:2852 beof = len(t.input) == 02853 if t.cx > 0 {2854 t.yanked = copySlice(t.input[:t.cx])358 unmodified linesmodified:test/test_go.rb+15 added
1603 unmodified lines1604 tmux.until { |lines| assert_equal '> 1000', lines[0] }1605 tmux.send_keys :Enter1606 end1607 1608+ def test_pos1609+ tmux.send_keys %(seq 1000 | #{FZF} --bind 'a:pos(3),b:pos(-3),c:pos(1),d:pos(-1),e:pos(0)' --preview 'echo {}/{}'), :Enter1610+ tmux.until { |lines| assert_equal 1000, lines.match_count }1611+ tmux.send_keys :a1612+ tmux.until { |lines| assert_includes lines[1], ' 3/3' }1613+ tmux.send_keys :b1614+ tmux.until { |lines| assert_includes lines[1], ' 998/998' }1615+ tmux.send_keys :c1616+ tmux.until { |lines| assert_includes lines[1], ' 1/1' }1617+ tmux.send_keys :d1618+ tmux.until { |lines| assert_includes lines[1], ' 1000/1000' }1619+ tmux.send_keys :e1620+ tmux.until { |lines| assert_includes lines[1], ' 1/1' }1621+ end1622+1623 def test_accept_non_empty1624 tmux.send_keys %(seq 1000 | #{fzf('--print-query --bind enter:accept-non-empty')}), :Enter1625 tmux.until { |lines| assert_equal 1000, lines.match_count }1626 tmux.send_keys 'foo'1318 unmodified linesmodified:CHANGELOG.md+9 added
10 unmodified lines11 12 # Send actions to the server13 curl -XPOST localhost:6266 -d 'reload(seq 100)+change-prompt(hundred> )'14 ```15+- Added `pos(...)` action to move the cursor to the numeric position16+ - `first` and `last` are equivalent to `pos(1)` and `pos(-1)` respectively17+ ```sh18+ # Put the cursor on the 10th item19+ seq 100 | fzf --sync --bind 'start:pos(10)'20+21+ # Put the cursor on the 10th to last item22+ seq 100 | fzf --sync --bind 'start:pos(-10)'23+ ```24 - Added `next-selected` and `prev-selected` actions to move between selected25 items26 ```sh27 # `next-selected` will move the pointer to the next selected item below the current line1406 unmodified lines