feat!(textinput): DefaultKeyMap is now a function; was formerly a global

This commit is contained in:
Christian Rocha
2024-10-31 15:02:05 -04:00
parent c560f6a021
commit 73fe314cc6
+4 -2
View File
@@ -62,7 +62,8 @@ type KeyMap struct {
// DefaultKeyMap is the default set of key bindings for navigating and acting // DefaultKeyMap is the default set of key bindings for navigating and acting
// upon the textinput. // upon the textinput.
var DefaultKeyMap = KeyMap{ func DefaultKeyMap() KeyMap {
return KeyMap{
CharacterForward: key.NewBinding(key.WithKeys("right", "ctrl+f")), CharacterForward: key.NewBinding(key.WithKeys("right", "ctrl+f")),
CharacterBackward: key.NewBinding(key.WithKeys("left", "ctrl+b")), CharacterBackward: key.NewBinding(key.WithKeys("left", "ctrl+b")),
WordForward: key.NewBinding(key.WithKeys("alt+right", "ctrl+right", "alt+f")), WordForward: key.NewBinding(key.WithKeys("alt+right", "ctrl+right", "alt+f")),
@@ -79,6 +80,7 @@ var DefaultKeyMap = KeyMap{
AcceptSuggestion: key.NewBinding(key.WithKeys("tab")), AcceptSuggestion: key.NewBinding(key.WithKeys("tab")),
NextSuggestion: key.NewBinding(key.WithKeys("down", "ctrl+n")), NextSuggestion: key.NewBinding(key.WithKeys("down", "ctrl+n")),
PrevSuggestion: key.NewBinding(key.WithKeys("up", "ctrl+p")), PrevSuggestion: key.NewBinding(key.WithKeys("up", "ctrl+p")),
}
} }
// Model is the Bubble Tea model for this text input element. // Model is the Bubble Tea model for this text input element.
@@ -157,7 +159,7 @@ func New() Model {
ShowSuggestions: false, ShowSuggestions: false,
CompletionStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("240")), CompletionStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("240")),
Cursor: cursor.New(), Cursor: cursor.New(),
KeyMap: DefaultKeyMap, KeyMap: DefaultKeyMap(),
suggestions: [][]rune{}, suggestions: [][]rune{},
value: nil, value: nil,