Separate handleCompletionKeyBinding
This commit is contained in:
parent
134d46302a
commit
f2ee1fd099
54
prompt.go
54
prompt.go
@ -105,31 +105,7 @@ func (p *Prompt) feed(b []byte) (shouldExit bool, exec *Exec) {
|
|||||||
|
|
||||||
// completion
|
// completion
|
||||||
completing := p.completion.Completing()
|
completing := p.completion.Completing()
|
||||||
switch key {
|
p.handleCompletionKeyBinding(key, completing)
|
||||||
case Down:
|
|
||||||
if completing {
|
|
||||||
p.completion.Next()
|
|
||||||
}
|
|
||||||
case Tab, ControlI:
|
|
||||||
p.completion.Next()
|
|
||||||
case Up:
|
|
||||||
if completing {
|
|
||||||
p.completion.Previous()
|
|
||||||
}
|
|
||||||
case BackTab:
|
|
||||||
p.completion.Previous()
|
|
||||||
case ControlSpace:
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
if s, ok := p.completion.GetSelectedSuggestion(); ok {
|
|
||||||
w := p.buf.Document().GetWordBeforeCursor()
|
|
||||||
if w != "" {
|
|
||||||
p.buf.DeleteBeforeCursor(len([]rune(w)))
|
|
||||||
}
|
|
||||||
p.buf.InsertText(s.Text, false, true)
|
|
||||||
}
|
|
||||||
p.completion.Reset()
|
|
||||||
}
|
|
||||||
|
|
||||||
switch key {
|
switch key {
|
||||||
case Enter, ControlJ, ControlM:
|
case Enter, ControlJ, ControlM:
|
||||||
@ -171,6 +147,34 @@ func (p *Prompt) feed(b []byte) (shouldExit bool, exec *Exec) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Prompt) handleCompletionKeyBinding(key Key, completing bool) {
|
||||||
|
switch key {
|
||||||
|
case Down:
|
||||||
|
if completing {
|
||||||
|
p.completion.Next()
|
||||||
|
}
|
||||||
|
case Tab, ControlI:
|
||||||
|
p.completion.Next()
|
||||||
|
case Up:
|
||||||
|
if completing {
|
||||||
|
p.completion.Previous()
|
||||||
|
}
|
||||||
|
case BackTab:
|
||||||
|
p.completion.Previous()
|
||||||
|
case ControlSpace:
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
if s, ok := p.completion.GetSelectedSuggestion(); ok {
|
||||||
|
w := p.buf.Document().GetWordBeforeCursor()
|
||||||
|
if w != "" {
|
||||||
|
p.buf.DeleteBeforeCursor(len([]rune(w)))
|
||||||
|
}
|
||||||
|
p.buf.InsertText(s.Text, false, true)
|
||||||
|
}
|
||||||
|
p.completion.Reset()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Prompt) handleKeyBinding(key Key) {
|
func (p *Prompt) handleKeyBinding(key Key) {
|
||||||
for i := range commonKeyBindings {
|
for i := range commonKeyBindings {
|
||||||
kb := commonKeyBindings[i]
|
kb := commonKeyBindings[i]
|
||||||
|
Loading…
Reference in New Issue
Block a user