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