feat(chat): toggle reply mentions from composer
This commit is contained in:
parent
5122bdea4a
commit
8f38996b8a
3 changed files with 45 additions and 15 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -92,12 +92,13 @@ type MessagesListKeybinds struct {
|
|||
}
|
||||
|
||||
type ComposerKeybinds struct {
|
||||
Paste Keybind `toml:"paste"`
|
||||
Send Keybind `toml:"send"`
|
||||
Newline Keybind `toml:"newline"`
|
||||
Cancel Keybind `toml:"cancel"`
|
||||
TabComplete Keybind `toml:"tab_complete"`
|
||||
Undo Keybind `toml:"undo"`
|
||||
Paste Keybind `toml:"paste"`
|
||||
Send Keybind `toml:"send"`
|
||||
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"`
|
||||
OpenFilePicker Keybind `toml:"open_file_picker"`
|
||||
|
|
@ -185,14 +186,15 @@ func defaultMessagesListKeybinds() MessagesListKeybinds {
|
|||
|
||||
func defaultComposerKeybinds() ComposerKeybinds {
|
||||
return ComposerKeybinds{
|
||||
Paste: desc("paste"),
|
||||
Send: desc("send"),
|
||||
Newline: desc("nl"),
|
||||
Cancel: desc("cancel"),
|
||||
TabComplete: desc("complete"),
|
||||
Undo: desc("undo"),
|
||||
OpenEditor: desc("editor"),
|
||||
OpenFilePicker: desc("attach"),
|
||||
Paste: desc("paste"),
|
||||
Send: desc("send"),
|
||||
Newline: desc("nl"),
|
||||
Cancel: desc("cancel"),
|
||||
TabComplete: desc("complete"),
|
||||
ToggleReplyMention: desc("toggle @reply"),
|
||||
Undo: desc("undo"),
|
||||
OpenEditor: desc("editor"),
|
||||
OpenFilePicker: desc("attach"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue