mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2025-01-11 02:36:12 +00:00
Add backward-eof event for --bind
This commit is contained in:
parent
06d63a862e
commit
a7aa08ce07
@ -635,12 +635,23 @@ e.g.
|
|||||||
or any single character
|
or any single character
|
||||||
|
|
||||||
.SS AVAILABLE EVENTS:
|
.SS AVAILABLE EVENTS:
|
||||||
\fIchange\fR (triggered whenever the query string is changed)
|
\fIchange\fR
|
||||||
.br
|
.RS
|
||||||
|
Triggered whenever the query string is changed
|
||||||
|
|
||||||
e.g.
|
e.g.
|
||||||
\fB# Moves cursor to the top (or bottom depending on --layout) whenever the query is changed
|
\fB# Moves cursor to the top (or bottom depending on --layout) whenever the query is changed
|
||||||
fzf --bind change:top\fR
|
fzf --bind change:top\fR
|
||||||
|
.RE
|
||||||
|
|
||||||
|
\fIbackward-eof\fR
|
||||||
|
.RS
|
||||||
|
Triggered when the query string is already empty and you try to delete it
|
||||||
|
backward.
|
||||||
|
|
||||||
|
e.g.
|
||||||
|
\fBfzf --bind backward-eof:abort\fR
|
||||||
|
.RE
|
||||||
|
|
||||||
.SS AVAILABLE ACTIONS:
|
.SS AVAILABLE ACTIONS:
|
||||||
A key or an event can be bound to one or more of the following actions.
|
A key or an event can be bound to one or more of the following actions.
|
||||||
|
@ -464,6 +464,8 @@ func parseKeyChords(str string, message string) map[int]string {
|
|||||||
chord = tui.CtrlRightBracket
|
chord = tui.CtrlRightBracket
|
||||||
case "change":
|
case "change":
|
||||||
chord = tui.Change
|
chord = tui.Change
|
||||||
|
case "backward-eof":
|
||||||
|
chord = tui.BackwardEOF
|
||||||
case "alt-enter", "alt-return":
|
case "alt-enter", "alt-return":
|
||||||
chord = tui.CtrlAltM
|
chord = tui.CtrlAltM
|
||||||
case "alt-space":
|
case "alt-space":
|
||||||
|
@ -1738,6 +1738,7 @@ func (t *Terminal) Loop() {
|
|||||||
for looping {
|
for looping {
|
||||||
var newCommand *string
|
var newCommand *string
|
||||||
changed := false
|
changed := false
|
||||||
|
beof := false
|
||||||
queryChanged := false
|
queryChanged := false
|
||||||
|
|
||||||
event := t.tui.GetChar()
|
event := t.tui.GetChar()
|
||||||
@ -1881,6 +1882,7 @@ func (t *Terminal) Loop() {
|
|||||||
t.cx++
|
t.cx++
|
||||||
}
|
}
|
||||||
case actBackwardDeleteChar:
|
case actBackwardDeleteChar:
|
||||||
|
beof = len(t.input) == 0
|
||||||
if t.cx > 0 {
|
if t.cx > 0 {
|
||||||
t.input = append(t.input[:t.cx-1], t.input[t.cx:]...)
|
t.input = append(t.input[:t.cx-1], t.input[t.cx:]...)
|
||||||
t.cx--
|
t.cx--
|
||||||
@ -1973,16 +1975,19 @@ func (t *Terminal) Loop() {
|
|||||||
t.vset(0)
|
t.vset(0)
|
||||||
req(reqList)
|
req(reqList)
|
||||||
case actUnixLineDiscard:
|
case actUnixLineDiscard:
|
||||||
|
beof = len(t.input) == 0
|
||||||
if t.cx > 0 {
|
if t.cx > 0 {
|
||||||
t.yanked = copySlice(t.input[:t.cx])
|
t.yanked = copySlice(t.input[:t.cx])
|
||||||
t.input = t.input[t.cx:]
|
t.input = t.input[t.cx:]
|
||||||
t.cx = 0
|
t.cx = 0
|
||||||
}
|
}
|
||||||
case actUnixWordRubout:
|
case actUnixWordRubout:
|
||||||
|
beof = len(t.input) == 0
|
||||||
if t.cx > 0 {
|
if t.cx > 0 {
|
||||||
t.rubout("\\s\\S")
|
t.rubout("\\s\\S")
|
||||||
}
|
}
|
||||||
case actBackwardKillWord:
|
case actBackwardKillWord:
|
||||||
|
beof = len(t.input) == 0
|
||||||
if t.cx > 0 {
|
if t.cx > 0 {
|
||||||
t.rubout(t.wordRubout)
|
t.rubout(t.wordRubout)
|
||||||
}
|
}
|
||||||
@ -2145,6 +2150,11 @@ func (t *Terminal) Loop() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if onEOFs, prs := t.keymap[tui.BackwardEOF]; beof && prs {
|
||||||
|
if !doActions(onEOFs, tui.BackwardEOF) {
|
||||||
|
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() {
|
||||||
|
@ -87,6 +87,7 @@ const (
|
|||||||
F12
|
F12
|
||||||
|
|
||||||
Change
|
Change
|
||||||
|
BackwardEOF
|
||||||
|
|
||||||
AltSpace
|
AltSpace
|
||||||
AltSlash
|
AltSlash
|
||||||
|
@ -1746,6 +1746,17 @@ class TestGoFZF < TestBase
|
|||||||
tmux.send_keys "seq 10000 | #{FZF} --read0 --keep-right", :Enter
|
tmux.send_keys "seq 10000 | #{FZF} --read0 --keep-right", :Enter
|
||||||
tmux.until { |lines| assert lines.any_include?('9999 10000') }
|
tmux.until { |lines| assert lines.any_include?('9999 10000') }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_backward_eof
|
||||||
|
tmux.send_keys "echo foo | #{FZF} --bind 'backward-eof:reload(seq 100)'", :Enter
|
||||||
|
tmux.until { |lines| lines.item_count == 1 && lines.match_count == 1 }
|
||||||
|
tmux.send_keys 'x'
|
||||||
|
tmux.until { |lines| lines.item_count == 1 && lines.match_count == 0 }
|
||||||
|
tmux.send_keys :BSpace
|
||||||
|
tmux.until { |lines| lines.item_count == 1 && lines.match_count == 1 }
|
||||||
|
tmux.send_keys :BSpace
|
||||||
|
tmux.until { |lines| lines.item_count == 100 && lines.match_count == 100 }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module TestShell
|
module TestShell
|
||||||
|
Loading…
Reference in New Issue
Block a user