mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-13 13:53:47 -05:00
Add change-query(...) action
This commit is contained in:
@@ -13,6 +13,7 @@ CHANGELOG
|
|||||||
# Both actions respect --layout option
|
# Both actions respect --layout option
|
||||||
seq 10 | fzf --multi --bind ctrl-n:next-selected,ctrl-p:prev-selected --layout reverse
|
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,
|
- `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.
|
so you don't have to repeat the same action twice in `--bind` in most cases.
|
||||||
```sh
|
```sh
|
||||||
|
|||||||
@@ -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(...)\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-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-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-screen\fR \fIctrl-l\fR
|
||||||
\fBclear-selection\fR (clear multi-selection)
|
\fBclear-selection\fR (clear multi-selection)
|
||||||
\fBclose\fR (close preview window if open, abort fzf otherwise)
|
\fBclose\fR (close preview window if open, abort fzf otherwise)
|
||||||
|
|||||||
@@ -889,7 +889,7 @@ func init() {
|
|||||||
// Backreferences are not supported.
|
// Backreferences are not supported.
|
||||||
// "~!@#$%^&*;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')
|
// "~!@#$%^&*;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')
|
||||||
executeRegexp = regexp.MustCompile(
|
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("[,:]+")
|
splitRegexp = regexp.MustCompile("[,:]+")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -912,6 +912,8 @@ func parseKeymap(keymap map[tui.Event][]*action, str string) {
|
|||||||
prefix = symbol + "unbind"
|
prefix = symbol + "unbind"
|
||||||
} else if strings.HasPrefix(src[1:], "rebind") {
|
} else if strings.HasPrefix(src[1:], "rebind") {
|
||||||
prefix = symbol + "rebind"
|
prefix = symbol + "rebind"
|
||||||
|
} else if strings.HasPrefix(src[1:], "change-query") {
|
||||||
|
prefix = symbol + "change-query"
|
||||||
} else if strings.HasPrefix(src[1:], "change-prompt") {
|
} else if strings.HasPrefix(src[1:], "change-prompt") {
|
||||||
prefix = symbol + "change-prompt"
|
prefix = symbol + "change-prompt"
|
||||||
} else if src[len(prefix)] == '-' {
|
} else if src[len(prefix)] == '-' {
|
||||||
@@ -1121,6 +1123,8 @@ func parseKeymap(keymap map[tui.Event][]*action, str string) {
|
|||||||
offset = len("change-preview")
|
offset = len("change-preview")
|
||||||
case actChangePrompt:
|
case actChangePrompt:
|
||||||
offset = len("change-prompt")
|
offset = len("change-prompt")
|
||||||
|
case actChangeQuery:
|
||||||
|
offset = len("change-query")
|
||||||
case actUnbind:
|
case actUnbind:
|
||||||
offset = len("unbind")
|
offset = len("unbind")
|
||||||
case actRebind:
|
case actRebind:
|
||||||
@@ -1180,6 +1184,8 @@ func isExecuteAction(str string) actionType {
|
|||||||
return actChangePreview
|
return actChangePreview
|
||||||
case "change-prompt":
|
case "change-prompt":
|
||||||
return actChangePrompt
|
return actChangePrompt
|
||||||
|
case "change-query":
|
||||||
|
return actChangeQuery
|
||||||
case "execute":
|
case "execute":
|
||||||
return actExecute
|
return actExecute
|
||||||
case "execute-silent":
|
case "execute-silent":
|
||||||
|
|||||||
@@ -266,6 +266,7 @@ const (
|
|||||||
actBackwardWord
|
actBackwardWord
|
||||||
actCancel
|
actCancel
|
||||||
actChangePrompt
|
actChangePrompt
|
||||||
|
actChangeQuery
|
||||||
actClearScreen
|
actClearScreen
|
||||||
actClearQuery
|
actClearQuery
|
||||||
actClearSelection
|
actClearSelection
|
||||||
@@ -2647,6 +2648,9 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
case actPrintQuery:
|
case actPrintQuery:
|
||||||
req(reqPrintQuery)
|
req(reqPrintQuery)
|
||||||
|
case actChangeQuery:
|
||||||
|
t.input = []rune(a.a)
|
||||||
|
t.cx = len(t.input)
|
||||||
case actChangePrompt:
|
case actChangePrompt:
|
||||||
t.prompt, t.promptLen = t.parsePrompt(a.a)
|
t.prompt, t.promptLen = t.parsePrompt(a.a)
|
||||||
req(reqPrompt)
|
req(reqPrompt)
|
||||||
|
|||||||
@@ -1764,6 +1764,14 @@ class TestGoFZF < TestBase
|
|||||||
tmux.until { |lines| assert_equal '>', lines.last }
|
tmux.until { |lines| assert_equal '>', lines.last }
|
||||||
end
|
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
|
def test_clear_selection
|
||||||
tmux.send_keys %(seq 100 | #{FZF} --multi --bind space:clear-selection), :Enter
|
tmux.send_keys %(seq 100 | #{FZF} --multi --bind space:clear-selection), :Enter
|
||||||
tmux.until { |lines| assert_equal 100, lines.match_count }
|
tmux.until { |lines| assert_equal 100, lines.match_count }
|
||||||
|
|||||||
Reference in New Issue
Block a user