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