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