mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-26 06:46:35 +00:00
Implement bindable "change" event and "top" action
# Move cursor to the top result whenever the query string is changed fzf --bind change:top Close #925
This commit is contained in:
parent
3a5086796d
commit
e1e3339770
@ -467,6 +467,11 @@ e.g. \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR
|
|||||||
\fIdouble-click\fR
|
\fIdouble-click\fR
|
||||||
or any single character
|
or any single character
|
||||||
|
|
||||||
|
Additionally, a special event named \fIchange\fR is available which is
|
||||||
|
triggered whenever the query string is changed.
|
||||||
|
|
||||||
|
e.g. \fBfzf --bind change:top\fR
|
||||||
|
|
||||||
\fBACTION: DEFAULT BINDINGS (NOTES):
|
\fBACTION: DEFAULT BINDINGS (NOTES):
|
||||||
\fBabort\fR \fIctrl-c ctrl-g ctrl-q esc\fR
|
\fBabort\fR \fIctrl-c ctrl-g ctrl-q esc\fR
|
||||||
\fBaccept\fR \fIenter double-click\fR
|
\fBaccept\fR \fIenter double-click\fR
|
||||||
@ -513,6 +518,7 @@ e.g. \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR
|
|||||||
\fBtoggle-preview-wrap\fR
|
\fBtoggle-preview-wrap\fR
|
||||||
\fBtoggle-sort\fR
|
\fBtoggle-sort\fR
|
||||||
\fBtoggle+up\fR \fIbtab (shift-tab)\fR
|
\fBtoggle+up\fR \fIbtab (shift-tab)\fR
|
||||||
|
\fBtop\fR (move to the top result)
|
||||||
\fBunix-line-discard\fR \fIctrl-u\fR
|
\fBunix-line-discard\fR \fIctrl-u\fR
|
||||||
\fBunix-word-rubout\fR \fIctrl-w\fR
|
\fBunix-word-rubout\fR \fIctrl-w\fR
|
||||||
\fBup\fR \fIctrl-k ctrl-p up\fR
|
\fBup\fR \fIctrl-k ctrl-p up\fR
|
||||||
|
@ -400,6 +400,8 @@ func parseKeyChords(str string, message string) map[int]string {
|
|||||||
chord = tui.BSpace
|
chord = tui.BSpace
|
||||||
case "ctrl-space":
|
case "ctrl-space":
|
||||||
chord = tui.CtrlSpace
|
chord = tui.CtrlSpace
|
||||||
|
case "change":
|
||||||
|
chord = tui.Change
|
||||||
case "alt-enter", "alt-return":
|
case "alt-enter", "alt-return":
|
||||||
chord = tui.CtrlAltM
|
chord = tui.CtrlAltM
|
||||||
case "alt-space":
|
case "alt-space":
|
||||||
@ -714,6 +716,8 @@ func parseKeymap(keymap map[int][]action, str string) {
|
|||||||
appendAction(actDown)
|
appendAction(actDown)
|
||||||
case "up":
|
case "up":
|
||||||
appendAction(actUp)
|
appendAction(actUp)
|
||||||
|
case "top":
|
||||||
|
appendAction(actTop)
|
||||||
case "page-up":
|
case "page-up":
|
||||||
appendAction(actPageUp)
|
appendAction(actPageUp)
|
||||||
case "page-down":
|
case "page-down":
|
||||||
|
@ -213,6 +213,7 @@ const (
|
|||||||
actExecuteSilent
|
actExecuteSilent
|
||||||
actExecuteMulti // Deprecated
|
actExecuteMulti // Deprecated
|
||||||
actSigStop
|
actSigStop
|
||||||
|
actTop
|
||||||
)
|
)
|
||||||
|
|
||||||
func toActions(types ...actionType) []action {
|
func toActions(types ...actionType) []action {
|
||||||
@ -1609,6 +1610,9 @@ func (t *Terminal) Loop() {
|
|||||||
req(reqClose)
|
req(reqClose)
|
||||||
case actClearScreen:
|
case actClearScreen:
|
||||||
req(reqRedraw)
|
req(reqRedraw)
|
||||||
|
case actTop:
|
||||||
|
t.vset(0)
|
||||||
|
req(reqList)
|
||||||
case actUnixLineDiscard:
|
case actUnixLineDiscard:
|
||||||
if t.cx > 0 {
|
if t.cx > 0 {
|
||||||
t.yanked = copySlice(t.input[:t.cx])
|
t.yanked = copySlice(t.input[:t.cx])
|
||||||
@ -1749,6 +1753,11 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
t.truncateQuery()
|
t.truncateQuery()
|
||||||
changed = string(previousInput) != string(t.input)
|
changed = string(previousInput) != string(t.input)
|
||||||
|
if onChanges, prs := t.keymap[tui.Change]; changed && prs {
|
||||||
|
if !doActions(onChanges, tui.Change) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if mapkey == tui.Rune {
|
if mapkey == tui.Rune {
|
||||||
if idx := strings.IndexRune(t.jumpLabels, event.Char); idx >= 0 && idx < t.maxItems() && idx < t.merger.Length() {
|
if idx := strings.IndexRune(t.jumpLabels, event.Char); idx >= 0 && idx < t.maxItems() && idx < t.merger.Length() {
|
||||||
|
@ -75,6 +75,8 @@ const (
|
|||||||
F11
|
F11
|
||||||
F12
|
F12
|
||||||
|
|
||||||
|
Change
|
||||||
|
|
||||||
AltSpace
|
AltSpace
|
||||||
AltSlash
|
AltSlash
|
||||||
AltBS
|
AltBS
|
||||||
|
@ -1304,6 +1304,20 @@ class TestGoFZF < TestBase
|
|||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
tmux.until { |lines| lines[-2] == prompt && lines[-1] == '1' }
|
tmux.until { |lines| lines[-2] == prompt && lines[-1] == '1' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_change_top
|
||||||
|
tmux.send_keys %[seq 1000 | #{FZF} --bind change:top], :Enter
|
||||||
|
tmux.until { |lines| lines.match_count == 1000 }
|
||||||
|
tmux.send_keys :Up
|
||||||
|
tmux.until { |lines| lines[-4] == '> 2' }
|
||||||
|
tmux.send_keys 1
|
||||||
|
tmux.until { |lines| lines[-3] == '> 1' }
|
||||||
|
tmux.send_keys :Up
|
||||||
|
tmux.until { |lines| lines[-4] == '> 10' }
|
||||||
|
tmux.send_keys 1
|
||||||
|
tmux.until { |lines| lines[-3] == '> 11' }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module TestShell
|
module TestShell
|
||||||
|
Loading…
Reference in New Issue
Block a user