feat(chat): toggle reply mentions from composer

This commit is contained in:
ayn2op 2026-09-02 20:00:33 -04:00
parent 5122bdea4a
commit 8f38996b8a
3 changed files with 45 additions and 15 deletions

View file

@ -189,6 +189,8 @@ newline = "shift+enter"
cancel = "esc"
# Complete usernames when mentioning
tab_complete = "tab"
# Toggle whether a reply mentions its author.
toggle_reply_mention = "shift+tab"
undo = "ctrl+u"
open_editor = "ctrl+e"

View file

@ -97,6 +97,7 @@ type ComposerKeybinds struct {
Newline Keybind `toml:"newline"`
Cancel Keybind `toml:"cancel"`
TabComplete Keybind `toml:"tab_complete"`
ToggleReplyMention Keybind `toml:"toggle_reply_mention"`
Undo Keybind `toml:"undo"`
OpenEditor Keybind `toml:"open_editor"`
@ -190,6 +191,7 @@ func defaultComposerKeybinds() ComposerKeybinds {
Newline: desc("nl"),
Cancel: desc("cancel"),
TabComplete: desc("complete"),
ToggleReplyMention: desc("toggle @reply"),
Undo: desc("undo"),
OpenEditor: desc("editor"),
OpenFilePicker: desc("attach"),

View file

@ -204,6 +204,9 @@ func (c *composer) Update(msg tview.Msg) tview.Cmd {
return c.tabComplete()
}
return c.forwardToTextArea(msg)
case keybind.Matches(msg, c.cfg.Keybinds.Composer.ToggleReplyMention.Keybind):
c.toggleReplyMention()
return nil
case keybind.Matches(msg, c.cfg.Keybinds.Composer.Undo.Keybind):
return c.forwardToTextArea(tcell.NewEventKey(tcell.KeyCtrlZ, "", tcell.ModNone))
}
@ -228,6 +231,21 @@ func (c *composer) Update(msg tview.Msg) tview.Cmd {
return c.TextArea.Update(msg)
}
func (c *composer) toggleReplyMention() {
data := c.sendMessageData
if data.Reference == nil || data.AllowedMentions == nil || data.AllowedMentions.RepliedUser == nil {
return
}
mention := !*data.AllowedMentions.RepliedUser
data.AllowedMentions.RepliedUser = option.Some(mention)
title := strings.TrimPrefix(c.Title(), "[@] ")
if mention {
title = "[@] " + title
}
c.SetTitle(title)
}
type imagePastedMsg []byte
func pasteImage() tview.Cmd {
@ -830,6 +848,9 @@ func (c *composer) ShortHelp() []keybind.Keybind {
cfg := c.cfg.Keybinds.Composer
short := []keybind.Keybind{cfg.Send.Keybind, cfg.Newline.Keybind, cfg.Cancel.Keybind, cfg.Paste.Keybind, cfg.OpenEditor.Keybind}
if c.sendMessageData.Reference != nil {
short = append(short, cfg.ToggleReplyMention.Keybind)
}
if c.canAttachFiles() {
short = append(short, cfg.OpenFilePicker.Keybind)
}
@ -853,8 +874,13 @@ func (c *composer) FullHelp() [][]keybind.Keybind {
openEditor = append(openEditor, cfg.OpenFilePicker.Keybind)
}
compose := []keybind.Keybind{cfg.Send.Keybind, cfg.Newline.Keybind, cfg.Cancel.Keybind, cfg.Undo.Keybind}
if c.sendMessageData.Reference != nil {
compose = append(compose, cfg.ToggleReplyMention.Keybind)
}
return [][]keybind.Keybind{
{cfg.Send.Keybind, cfg.Newline.Keybind, cfg.Cancel.Keybind, cfg.Undo.Keybind},
compose,
openEditor,
}
}