summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2022-12-27 01:01:06 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2022-12-27 01:08:42 +0900
commit12af069dcad672b1563388c61ec33ba8a86c013e (patch)
tree887acd14cfe3ee74b6e181129765e27d9660fcb6 /src
parentd42e708d3140aab099b30014a9cbebafb8b66692 (diff)
downloadfzf-12af069dcad672b1563388c61ec33ba8a86c013e.tar.gz
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
Diffstat (limited to 'src')
-rw-r--r--src/options.go4
-rw-r--r--src/terminal.go11
2 files changed, 14 insertions, 1 deletions
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 {