on main help sign in
feat: open commands dialog on pressing `/` (#2034)
aa2cacdAndrey Nering
internal/ui/model/keys.go+5
@@ -10,6 +10,7 @@ type KeyMap struct {
10 Newline key.Binding
10 Newline key.Binding
11 AddImage key.Binding
11 AddImage key.Binding
12 MentionFile key.Binding
12 MentionFile key.Binding
13+ Commands key.Binding
13
14
14 // Attachments key maps
15 // Attachments key maps
15 AttachmentDeleteMode key.Binding
16 AttachmentDeleteMode key.Binding
@@ -123,6 +124,10 @@ func DefaultKeyMap() KeyMap {
123 key.WithKeys("@"),
124 key.WithKeys("@"),
124 key.WithHelp("@", "mention file"),
125 key.WithHelp("@", "mention file"),
125 )
126 )
127+ km.Editor.Commands = key.NewBinding(
128+ key.WithKeys("/"),
129+ key.WithHelp("/", "commands"),
130+ )
126 km.Editor.AttachmentDeleteMode = key.NewBinding(
131 km.Editor.AttachmentDeleteMode = key.NewBinding(
127 key.WithKeys("ctrl+r"),
132 key.WithKeys("ctrl+r"),
128 key.WithHelp("ctrl+r+{i}", "delete attachment at index i"),
133 key.WithHelp("ctrl+r+{i}", "delete attachment at index i"),
internal/ui/model/ui.go+6−2
@@ -1542,6 +1542,10 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
1542 if cmd != nil {
1542 if cmd != nil {
1543 cmds = append(cmds, cmd)
1543 cmds = append(cmds, cmd)
1544 }
1544 }
1545+ case key.Matches(msg, m.keyMap.Editor.Commands) && m.textarea.Value() == "":
1546+ if cmd := m.openCommandsDialog(); cmd != nil {
1547+ cmds = append(cmds, cmd)
1548+ }
1545 default:
1549 default:
1546 if handleGlobalKeys(msg) {
1550 if handleGlobalKeys(msg) {
1547 // Handle global keys first before passing to textarea.
1551 // Handle global keys first before passing to textarea.
@@ -1865,7 +1869,7 @@ func (m *UI) ShortHelp() []key.Binding {
1865 k := &m.keyMap
1869 k := &m.keyMap
1866 tab := k.Tab
1870 tab := k.Tab
1867 commands := k.Commands
1871 commands := k.Commands
1868− if m.focus == uiFocusEditor && m.textarea.LineCount() == 0 {
1872+ if m.focus == uiFocusEditor && m.textarea.Value() == "" {
1869 commands.SetHelp("/ or ctrl+p", "commands")
1873 commands.SetHelp("/ or ctrl+p", "commands")
1870 }
1874 }
1871
1875
@@ -1941,7 +1945,7 @@ func (m *UI) FullHelp() [][]key.Binding {
1941 hasAttachments := len(m.attachments.List()) > 0
1945 hasAttachments := len(m.attachments.List()) > 0
1942 hasSession := m.hasSession()
1946 hasSession := m.hasSession()
1943 commands := k.Commands
1947 commands := k.Commands
1944− if m.focus == uiFocusEditor && m.textarea.LineCount() == 0 {
1948+ if m.focus == uiFocusEditor && m.textarea.Value() == "" {
1945 commands.SetHelp("/ or ctrl+p", "commands")
1949 commands.SetHelp("/ or ctrl+p", "commands")
1946 }
1950 }
1947
1951