Add completionOnDown option

This commit is contained in:
VonC 2019-08-26 18:25:26 +02:00
parent df850582f4
commit 49fa645ffe
2 changed files with 10 additions and 1 deletions

View File

@ -206,6 +206,14 @@ func OptionSwitchKeyBindMode(m KeyBindMode) Option {
}
}
// OptionSwitchKeyBindMode set a key bind mode.
func OptionCompletionOnDown() Option {
return func(p *Prompt) error {
p.completionOnDown = true
return nil
}
}
// SwitchKeyBindMode to set a key bind mode.
// Deprecated: Please use OptionSwitchKeyBindMode.
var SwitchKeyBindMode = OptionSwitchKeyBindMode

View File

@ -25,6 +25,7 @@ type Prompt struct {
keyBindings []KeyBind
ASCIICodeBindings []ASCIICodeBind
keyBindMode KeyBindMode
completionOnDown bool
}
// Exec is the struct contains user input context.
@ -126,7 +127,7 @@ func (p *Prompt) feed(b []byte) (shouldExit bool, exec *Exec) {
if !completing { // Don't use p.completion.Completing() because it takes double operation when switch to selected=-1.
if newBuf, changed := p.history.Newer(p.buf); changed {
p.buf = newBuf
} else {
} else if p.completionOnDown {
p.completion.Next()
}
return