Add ^U, ^B and ^F keybindings

This commit is contained in:
Christian Rocha 2020-01-29 22:25:39 -05:00
parent 127afac006
commit 23f5f33283
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018

View File

@ -43,11 +43,15 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
m.pos--
}
return m, nil
case tea.KeyCtrlF: // ^F, forward one character
fallthrough
case tea.KeyLeft:
if m.pos > 0 {
m.pos--
}
return m, nil
case tea.KeyCtrlB: // ^B, back one charcter
fallthrough
case tea.KeyRight:
if m.pos < len(m.Value) {
m.pos++
@ -68,6 +72,10 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
m.Value = m.Value[:m.pos]
m.pos = len(m.Value)
return m, nil
case tea.KeyCtrlU: // ^U, kill text before cursor
m.Value = m.Value[m.pos:]
m.pos = 0
return m, nil
case tea.KeyRune:
m.Value = m.Value[:m.pos] + msg.String() + m.Value[m.pos:]
m.pos++