Skip to content

Commit

Permalink
feat: alt+enter / ctrl+j for new line in textarea, enter for next
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Nov 13, 2023
1 parent 4a6de6b commit 6ae9761
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion field_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 6ae9761

Please sign in to comment.