keys.go

 1package editor
 2
 3import (
 4	"github.com/charmbracelet/bubbles/v2/key"
 5)
 6
 7type EditorKeyMap struct {
 8	AddFile     key.Binding
 9	SendMessage key.Binding
10	OpenEditor  key.Binding
11	Newline     key.Binding
12}
13
14func DefaultEditorKeyMap() EditorKeyMap {
15	return EditorKeyMap{
16		AddFile: key.NewBinding(
17			key.WithKeys("/"),
18			key.WithHelp("/", "add file"),
19		),
20		SendMessage: key.NewBinding(
21			key.WithKeys("enter"),
22			key.WithHelp("enter", "send"),
23		),
24		OpenEditor: key.NewBinding(
25			key.WithKeys("ctrl+e"),
26			key.WithHelp("ctrl+e", "open editor"),
27		),
28		Newline: key.NewBinding(
29			key.WithKeys("shift+enter", "ctrl+j"),
30			key.WithHelp("shift+enter", "newline"), key.WithHelp("ctrl+j", "newline"),
31		),
32	}
33}
34
35// KeyBindings implements layout.KeyMapProvider
36func (k EditorKeyMap) KeyBindings() []key.Binding {
37	return []key.Binding{
38		k.AddFile,
39		k.SendMessage,
40		k.OpenEditor,
41		k.Newline,
42	}
43}
44
45type DeleteAttachmentKeyMaps struct {
46	AttachmentDeleteMode key.Binding
47	Escape               key.Binding
48	DeleteAllAttachments key.Binding
49}
50
51// TODO: update this to use the new keymap concepts
52var AttachmentsKeyMaps = DeleteAttachmentKeyMaps{
53	AttachmentDeleteMode: key.NewBinding(
54		key.WithKeys("ctrl+r"),
55		key.WithHelp("ctrl+r+{i}", "delete attachment at index i"),
56	),
57	Escape: key.NewBinding(
58		key.WithKeys("esc"),
59		key.WithHelp("esc", "cancel delete mode"),
60	),
61	DeleteAllAttachments: key.NewBinding(
62		key.WithKeys("r"),
63		key.WithHelp("ctrl+r+r", "delete all attachments"),
64	),
65}