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	Next        key.Binding
13	Previous    key.Binding
14}
15
16func DefaultEditorKeyMap() EditorKeyMap {
17	return EditorKeyMap{
18		AddFile: key.NewBinding(
19			key.WithKeys("/"),
20			key.WithHelp("/", "add file"),
21		),
22		SendMessage: key.NewBinding(
23			key.WithKeys("enter"),
24			key.WithHelp("enter", "send"),
25		),
26		OpenEditor: key.NewBinding(
27			key.WithKeys("ctrl+o"),
28			key.WithHelp("ctrl+o", "open editor"),
29		),
30		Newline: key.NewBinding(
31			key.WithKeys("shift+enter", "ctrl+j"),
32			// "ctrl+j" is a common keybinding for newline in many editors. If
33			// the terminal supports "shift+enter", we substitute the help text
34			// to reflect that.
35			key.WithHelp("ctrl+j", "newline"),
36		),
37		Next: key.NewBinding(
38			key.WithKeys("shift+down"),
39			key.WithHelp("shift+↓", "down"),
40		),
41		Previous: key.NewBinding(
42			key.WithKeys("shift+up"),
43			key.WithHelp("shift+↑", "up"),
44		),
45	}
46}
47
48// KeyBindings implements layout.KeyMapProvider
49func (k EditorKeyMap) KeyBindings() []key.Binding {
50	return []key.Binding{
51		k.AddFile,
52		k.SendMessage,
53		k.OpenEditor,
54		k.Newline,
55		AttachmentsKeyMaps.AttachmentDeleteMode,
56		AttachmentsKeyMaps.DeleteAllAttachments,
57		AttachmentsKeyMaps.Escape,
58	}
59}
60
61type DeleteAttachmentKeyMaps struct {
62	AttachmentDeleteMode key.Binding
63	Escape               key.Binding
64	DeleteAllAttachments key.Binding
65}
66
67// TODO: update this to use the new keymap concepts
68var AttachmentsKeyMaps = DeleteAttachmentKeyMaps{
69	AttachmentDeleteMode: key.NewBinding(
70		key.WithKeys("ctrl+r"),
71		key.WithHelp("ctrl+r+{i}", "delete attachment at index i"),
72	),
73	Escape: key.NewBinding(
74		key.WithKeys("esc", "alt+esc"),
75		key.WithHelp("esc", "cancel delete mode"),
76	),
77	DeleteAllAttachments: key.NewBinding(
78		key.WithKeys("r"),
79		key.WithHelp("ctrl+r+r", "delete all attachments"),
80	),
81}