summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--man/man1/fzf.11
-rw-r--r--src/options.go8
-rw-r--r--src/terminal.go4
-rwxr-xr-xtest/test_go.rb8
5 files changed, 21 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 123e9a10..9e239f1d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@ CHANGELOG
# Both actions respect --layout option
seq 10 | fzf --multi --bind ctrl-n:next-selected,ctrl-p:prev-selected --layout reverse
```
+- Added `change-query(...)` action
- `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 03ac6551..a4072326 100644
--- a/man/man1/fzf.1
+++ b/man/man1/fzf.1
@@ -950,6 +950,7 @@ A key or an event can be bound to one or more of the following actions.
\fBchange-preview(...)\fR (change \fB--preview\fR option)
\fBchange-preview-window(...)\fR (change \fB--preview-window\fR option; rotate through the multiple option sets separated by '|')
\fBchange-prompt(...)\fR (change prompt to the given string)
+ \fBchange-query(...)\fR (change query string to the given string)
\fBclear-screen\fR \fIctrl-l\fR
\fBclear-selection\fR (clear multi-selection)
\fBclose\fR (close preview window if open, abort fzf otherwise)
diff --git a/src/options.go b/src/options.go
index 4728adff..64cf5609 100644
--- a/src/options.go
+++ b/src/options.go
@@ -889,7 +889,7 @@ func init() {
// Backreferences are not supported.
// "~!@#$%^&*;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')
executeRegexp = regexp.MustCompile(
- `(?si)[:+](execute(?:-multi|-silent)?|reload|preview|change-prompt|change-preview-window|change-preview|(?:re|un)bind):.+|[:+](execute(?:-multi|-silent)?|reload|preview|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):.+|[:+](execute(?:-multi|-silent)?|reload|preview|change-query|change-prompt|change-preview-window|change-preview|(?:re|un)bind)(\([^)]*\)|\[[^\]]*\]|~[^~]*~|![^!]*!|@[^@]*@|\#[^\#]*\#|\$[^\$]*\$|%[^%]*%|\^[^\^]*\^|&[^&]*&|\*[^\*]*\*|;[^;]*;|/[^/]*/|\|[^\|]*\|)`)
splitRegexp = regexp.MustCompile("[,:]+")
}
@@ -912,6 +912,8 @@ func parseKeymap(keymap map[tui.Event][]*action, str string) {
prefix = symbol + "unbind"
} else if strings.HasPrefix(src[1:], "rebind") {
prefix = symbol + "rebind"
+ } else if strings.HasPrefix(src[1:], "change-query") {
+ prefix = symbol + "change-query"
} else if strings.HasPrefix(src[1:], "change-prompt") {
prefix = symbol + "change-prompt"
} else if src[len(prefix)] == '-' {
@@ -1121,6 +1123,8 @@ func parseKeymap(keymap map[tui.Event][]*action, str string) {
offset = len("change-preview")
case actChangePrompt:
offset = len("change-prompt")
+ case actChangeQuery:
+ offset = len("change-query")
case actUnbind:
offset = len("unbind")
case actRebind:
@@ -1180,6 +1184,8 @@ func isExecuteAction(str string) actionType {
return actChangePreview
case "change-prompt":
return actChangePrompt
+ case "change-query":
+ return actChangeQuery
case "execute":
return actExecute
case "execute-silent":
diff --git a/src/terminal.go b/src/terminal.go
index 2bb785c1..e0ff5b2b 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -266,6 +266,7 @@ const (
actBackwardWord
actCancel
actChangePrompt
+ actChangeQuery
actClearScreen
actClearQuery
actClearSelection
@@ -2647,6 +2648,9 @@ func (t *Terminal) Loop() {
}
case actPrintQuery:
req(reqPrintQuery)
+ case actChangeQuery:
+ t.input = []rune(a.a)
+ t.cx = len(t.input)
case actChangePrompt:
t.prompt, t.promptLen = t.parsePrompt(a.a)
req(reqPrompt)
diff --git a/test/test_go.rb b/test/test_go.rb
index 2312848b..5bffaaf9 100755
--- a/test/test_go.rb
+++ b/test/test_go.rb
@@ -1764,6 +1764,14 @@ class TestGoFZF < TestBase
tmux.until { |lines| assert_equal '>', lines.last }
end
+ def test_change_query
+ tmux.send_keys %(: | #{FZF} --query foo --bind space:change-query:foobar), :Enter
+ tmux.until { |lines| assert_equal 0, lines.item_count }
+ tmux.until { |lines| assert_equal '> foo', lines.last }
+ tmux.send_keys :Space, 'baz'
+ tmux.until { |lines| assert_equal '> foobarbaz', lines.last }
+ end
+
def test_clear_selection
tmux.send_keys %(seq 100 | #{FZF} --multi --bind space:clear-selection), :Enter
tmux.until { |lines| assert_equal 100, lines.match_count }