Support Alt-Backspace to delete previous word

This commit is contained in:
Christian Muehlhaeuser 2020-10-27 08:50:22 +01:00
parent 5dbcf95877
commit 97020cd0d2
No known key found for this signature in database
GPG Key ID: 3CF9FA45CA1EBB7E

View File

@ -418,10 +418,14 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
case tea.KeyMsg: case tea.KeyMsg:
switch msg.Type { switch msg.Type {
case tea.KeyBackspace: // delete character before cursor case tea.KeyBackspace: // delete character before cursor
if len(m.value) > 0 { if msg.Alt {
m.value = append(m.value[:max(0, m.pos-1)], m.value[m.pos:]...) m.deleteWordLeft()
if m.pos > 0 { } else {
m.SetCursor(m.pos - 1) if len(m.value) > 0 {
m.value = append(m.value[:max(0, m.pos-1)], m.value[m.pos:]...)
if m.pos > 0 {
m.SetCursor(m.pos - 1)
}
} }
} }
case tea.KeyLeft: case tea.KeyLeft: