feat: implement reply to selected message functionality (#39)
* feat: implement reply to selected message functionality * docs: add keybinding for reply
This commit is contained in:
parent
5d19c768fe
commit
23afb2ecef
3 changed files with 25 additions and 2 deletions
|
|
@ -55,6 +55,7 @@ TextView:
|
|||
- `j` or `Down`: Selects the message just after the currently selected message.
|
||||
- `g` or `Home`: Selects the first message rendered in the TextView.
|
||||
- `G` or `End`: Selects the last message rendered in the TextView.
|
||||
- `r`: Reply to the selected message.
|
||||
|
||||
### Clipboard
|
||||
|
||||
|
|
|
|||
23
discordo.go
23
discordo.go
|
|
@ -24,6 +24,7 @@ var (
|
|||
config *util.Config
|
||||
session *discordgo.Session
|
||||
selectedChannel *discordgo.Channel
|
||||
selectedMessage *discordgo.Message
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -174,6 +175,21 @@ func onMessagesTextViewInputCapture(e *tcell.EventKey) *tcell.EventKey {
|
|||
messagesTextView.
|
||||
Highlight(ms[0].ID).
|
||||
ScrollToHighlight()
|
||||
case e.Rune() == 'r': // Reply
|
||||
hs := messagesTextView.GetHighlights()
|
||||
if len(hs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, m := range selectedChannel.Messages {
|
||||
if m.ID == hs[0] {
|
||||
selectedMessage = m
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
messageInputField.SetTitle("Replying to " + selectedMessage.Author.Username)
|
||||
app.SetFocus(messageInputField)
|
||||
}
|
||||
|
||||
return e
|
||||
|
|
@ -191,8 +207,13 @@ func onMessageInputFieldInputCapture(e *tcell.EventKey) *tcell.EventKey {
|
|||
return nil
|
||||
}
|
||||
|
||||
if selectedMessage != nil {
|
||||
go session.ChannelMessageSendReply(selectedMessage.ChannelID, t, selectedMessage.Reference())
|
||||
} else {
|
||||
go session.ChannelMessageSend(selectedChannel.ID, t)
|
||||
}
|
||||
|
||||
messageInputField.SetText("")
|
||||
go session.ChannelMessageSend(selectedChannel.ID, t)
|
||||
case tcell.KeyCtrlV:
|
||||
text, _ := clipboard.ReadAll()
|
||||
text = messageInputField.GetText() + text
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ func NewMessageInputField(
|
|||
SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor).
|
||||
SetInputCapture(onMessageInputFieldInputCapture).
|
||||
SetBorder(true).
|
||||
SetBorderPadding(0, 0, 1, 0)
|
||||
SetBorderPadding(0, 0, 1, 0).
|
||||
SetTitleAlign(tview.AlignLeft)
|
||||
|
||||
return i
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue