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:
Junegunn Choi
2017-05-22 17:07:05 +09:00
parent 3a5086796d
commit e1e3339770
5 changed files with 35 additions and 0 deletions

View File

@@ -213,6 +213,7 @@ const (
actExecuteSilent
actExecuteMulti // Deprecated
actSigStop
actTop
)
func toActions(types ...actionType) []action {
@@ -1609,6 +1610,9 @@ func (t *Terminal) Loop() {
req(reqClose)
case actClearScreen:
req(reqRedraw)
case actTop:
t.vset(0)
req(reqList)
case actUnixLineDiscard:
if t.cx > 0 {
t.yanked = copySlice(t.input[:t.cx])
@@ -1749,6 +1753,11 @@ func (t *Terminal) Loop() {
}
t.truncateQuery()
changed = string(previousInput) != string(t.input)
if onChanges, prs := t.keymap[tui.Change]; changed && prs {
if !doActions(onChanges, tui.Change) {
continue
}
}
} else {
if mapkey == tui.Rune {
if idx := strings.IndexRune(t.jumpLabels, event.Char); idx >= 0 && idx < t.maxItems() && idx < t.merger.Length() {