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,12 +418,16 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
case tea.KeyMsg:
switch msg.Type {
case tea.KeyBackspace: // delete character before cursor
if msg.Alt {
m.deleteWordLeft()
} else {
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:
if msg.Alt { // alt+left arrow, back one word
m.wordLeft()