From 6ae9761e12bca839e870ec2b23ecd37ff15dcd23 Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Mon, 13 Nov 2023 13:50:06 -0500 Subject: [PATCH] feat: alt+enter / ctrl+j for new line in textarea, enter for next --- field_text.go | 3 ++- keymap.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/field_text.go b/field_text.go index 39879b4c..a507e2bd 100644 --- a/field_text.go +++ b/field_text.go @@ -152,7 +152,7 @@ func (t *Text) Blur() tea.Cmd { // KeyBinds returns the help message for the text field. func (t *Text) KeyBinds() []key.Binding { - return []key.Binding{t.keymap.Next, t.keymap.Editor, t.keymap.Prev} + return []key.Binding{t.keymap.Next, t.keymap.NewLine, t.keymap.Editor, t.keymap.Prev} } type updateValueMsg []byte @@ -262,6 +262,7 @@ func (t *Text) WithTheme(theme *Theme) Field { // WithKeyMap sets the keymap on a text field. func (t *Text) WithKeyMap(k *KeyMap) Field { t.keymap = &k.Text + t.textarea.KeyMap.InsertNewline.SetKeys(t.keymap.NewLine.Keys()...) return t } diff --git a/keymap.go b/keymap.go index a4201ea8..b6b0f958 100644 --- a/keymap.go +++ b/keymap.go @@ -70,9 +70,9 @@ func NewDefaultKeyMap() *KeyMap { Prev: key.NewBinding(key.WithKeys("shift+tab"), key.WithHelp("shift+tab", "back")), }, Text: TextKeyMap{ - Next: key.NewBinding(key.WithKeys("tab"), key.WithHelp("tab", "next")), + Next: key.NewBinding(key.WithKeys("tab", "enter"), key.WithHelp("enter", "next")), Prev: key.NewBinding(key.WithKeys("shift+tab"), key.WithHelp("shift+tab", "back")), - NewLine: key.NewBinding(key.WithKeys("enter"), key.WithHelp("enter", "new line")), + NewLine: key.NewBinding(key.WithKeys("alt+enter", "ctrl+j"), key.WithHelp("alt+enter / ctrl+j", "new line")), Editor: key.NewBinding(key.WithKeys("ctrl+e"), key.WithHelp("ctrl+e", "open editor")), }, Select: SelectKeyMap{