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+v"),
26			key.WithHelp("ctrl+v", "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	}
46}
47
48type DeleteAttachmentKeyMaps struct {
49	AttachmentDeleteMode key.Binding
50	Escape               key.Binding
51	DeleteAllAttachments key.Binding
52}
53
54// TODO: update this to use the new keymap concepts
55var AttachmentsKeyMaps = DeleteAttachmentKeyMaps{
56	AttachmentDeleteMode: key.NewBinding(
57		key.WithKeys("ctrl+r"),
58		key.WithHelp("ctrl+r+{i}", "delete attachment at index i"),
59	),
60	Escape: key.NewBinding(
61		key.WithKeys("esc"),
62		key.WithHelp("esc", "cancel delete mode"),
63	),
64	DeleteAllAttachments: key.NewBinding(
65		key.WithKeys("r"),
66		key.WithHelp("ctrl+r+r", "delete all attachments"),
67	),
68}