From 12af069dcad672b1563388c61ec33ba8a86c013e Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 27 Dec 2022 01:01:06 +0900 Subject: Add pos(...) action to move the cursor to the numeric position # 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 --- src/options.go | 4 +++- src/terminal.go | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/options.go b/src/options.go index 1fb649f2..91ac9881 100644 --- a/src/options.go +++ b/src/options.go @@ -890,7 +890,7 @@ const ( func init() { executeRegexp = regexp.MustCompile( - `(?si)[:+](execute(?:-multi|-silent)?|reload|preview|change-query|change-prompt|change-preview-window|change-preview|(?:re|un)bind)`) + `(?si)[:+](execute(?:-multi|-silent)?|reload|preview|change-query|change-prompt|change-preview-window|change-preview|(?:re|un)bind|pos)`) splitRegexp = regexp.MustCompile("[,:]+") actionNameRegexp = regexp.MustCompile("(?i)^[a-z-]+") } @@ -1197,6 +1197,8 @@ func isExecuteAction(str string) actionType { return actChangePrompt case "change-query": return actChangeQuery + case "pos": + return actPosition case "execute": return actExecute case "execute-silent": diff --git a/src/terminal.go b/src/terminal.go index d0c0a9de..90239f7b 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -297,6 +297,7 @@ const ( actUp actPageUp actPageDown + actPosition actHalfPageUp actHalfPageDown actJump @@ -2837,6 +2838,16 @@ func (t *Terminal) Loop() { case actLast: t.vset(t.merger.Length() - 1) req(reqList) + case actPosition: + if n, e := strconv.Atoi(a.a); e == nil { + if n > 0 { + n-- + } else if n < 0 { + n += t.merger.Length() + } + t.vset(n) + req(reqList) + } case actUnixLineDiscard: beof = len(t.input) == 0 if t.cx > 0 { -- cgit v1.2.3