summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2022-12-27 19:54:46 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2022-12-27 19:54:46 +0900
commit4b3f0b9f083ffff69b432b4d01eaab11d2cf58b9 (patch)
treec74604cadc902f6121e2e583d25c09d777f803cb
parent12af069dcad672b1563388c61ec33ba8a86c013e (diff)
Allow put action with an argument i.e. put(...)
-rw-r--r--CHANGELOG.md5
-rw-r--r--man/man1/fzf.11
-rw-r--r--src/options.go4
-rw-r--r--src/terminal.go6
-rwxr-xr-xtest/test_go.rb9
5 files changed, 24 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f4847e3f..0ae8edaa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,11 @@ CHANGELOG
seq 10 | fzf --multi --bind ctrl-n:next-selected,ctrl-p:prev-selected --layout reverse
```
- Added `change-query(...)` action
+- `put` action can optionally take an argument string
+ ```sh
+ # a will put 'alpha' on the prompt, ctrl-b will put 'bravo'
+ fzf --bind 'a:put+put(lpha),ctrl-b:put(bravo)'
+ ```
- `double-click` will behave the same as `enter` unless otherwise specified,
so you don't have to repeat the same action twice in `--bind` in most cases.
```sh
diff --git a/man/man1/fzf.1 b/man/man1/fzf.1
index 17c7dd21..2661904e 100644
--- a/man/man1/fzf.1
+++ b/man/man1/fzf.1
@@ -1008,6 +1008,7 @@ A key or an event can be bound to one or more of the following actions.
\fBpreview-top\fR
\fBprint-query\fR (print query and exit)
\fBput\fR (put the character to the prompt)
+ \fBput(...)\fR (put the given string to the prompt)
\fBrefresh-preview\fR
\fBrebind(...)\fR (rebind bindings after \fBunbind\fR)
\fBreload(...)\fR (see below for the details)
diff --git a/src/options.go b/src/options.go
index 91ac9881..f25b6e73 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|pos)`)
+ `(?si)[:+](execute(?:-multi|-silent)?|reload|preview|change-query|change-prompt|change-preview-window|change-preview|(?:re|un)bind|pos|put)`)
splitRegexp = regexp.MustCompile("[,:]+")
actionNameRegexp = regexp.MustCompile("(?i)^[a-z-]+")
}
@@ -1205,6 +1205,8 @@ func isExecuteAction(str string) actionType {
return actExecuteSilent
case "execute-multi":
return actExecuteMulti
+ case "put":
+ return actPut
}
return actIgnore
}
diff --git a/src/terminal.go b/src/terminal.go
index 90239f7b..552daa23 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -321,6 +321,7 @@ const (
actPreviewHalfPageDown
actPrevHistory
actPrevSelected
+ actPut
actNextHistory
actNextSelected
actExecute
@@ -2848,6 +2849,11 @@ func (t *Terminal) Loop() {
t.vset(n)
req(reqList)
}
+ case actPut:
+ str := []rune(a.a)
+ suffix := copySlice(t.input[t.cx:])
+ t.input = append(append(t.input[:t.cx], str...), suffix...)
+ t.cx += len(str)
case actUnixLineDiscard:
beof = len(t.input) == 0
if t.cx > 0 {
diff --git a/test/test_go.rb b/test/test_go.rb
index 2956d189..4b2856eb 100755
--- a/test/test_go.rb
+++ b/test/test_go.rb
@@ -1620,6 +1620,15 @@ class TestGoFZF < TestBase
tmux.until { |lines| assert_includes lines[1], ' 1/1' }
end
+ def test_put
+ tmux.send_keys %(seq 1000 | #{FZF} --bind 'a:put+put,b:put+put(ravo)' --preview 'echo {q}/{q}'), :Enter
+ tmux.until { |lines| assert_equal 1000, lines.match_count }
+ tmux.send_keys :a
+ tmux.until { |lines| assert_includes lines[1], ' aa/aa' }
+ tmux.send_keys :b
+ tmux.until { |lines| assert_includes lines[1], ' aabravo/aabravo' }
+ end
+
def test_accept_non_empty
tmux.send_keys %(seq 1000 | #{fzf('--print-query --bind enter:accept-non-empty')}), :Enter
tmux.until { |lines| assert_equal 1000, lines.match_count }