feat: select selected message's referenced message using keybinding (#87)

* feat: jump to referenced message using keybinding

* Rename JumpToSelectedMessageReference to JumpSelectedMessageReference

* Remove 'to' from toml tag

* Rename JumpSelectedMessageReference to SelectMessageReference
This commit is contained in:
ayntgl 2021-10-28 22:03:05 +04:00 • committed by GitHub
parent cfee278be8
commit cc45f6b6bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 7 deletions

View file

@ -21,6 +21,7 @@ type keybindings struct {
SelectNextMessage string `toml:"select_next_message"`
SelectFirstMessage string `toml:"select_first_message"`
SelectLastMessage string `toml:"select_last_message"`
SelectMessageReference string `toml:"select_message_reference"`
ReplySelectedMessage string `toml:"reply_selected_message"`
MentionReplySelectedMessage string `toml:"mention_reply_selected_message"`
CopySelectedMessage string `toml:"copy_selected_message"`
@ -109,6 +110,7 @@ func loadConfig() *config {
ReplySelectedMessage: "Rune[r]",
MentionReplySelectedMessage: "Rune[R]",
CopySelectedMessage: "Rune[c]",
SelectMessageReference: "Rune[m]",
}
c.Borders = tview.Borders

21
ui.go
View file

@ -178,13 +178,28 @@ func onMessagesViewInputCapture(e *tcell.EventKey) *tcell.EventKey {
Highlight(ms[selectedMessage].ID).
ScrollToHighlight()
return nil
case conf.Keybindings.SelectMessageReference:
hs := messagesView.GetHighlights()
if len(hs) == 0 {
return nil
}
_, m := findByMessageID(hs[0])
if m.ReferencedMessage != nil {
selectedMessage, _ = findByMessageID(m.ReferencedMessage.ID)
messagesView.
Highlight(m.ReferencedMessage.ID).
ScrollToHighlight()
}
return nil
case conf.Keybindings.ReplySelectedMessage:
hs := messagesView.GetHighlights()
if len(hs) == 0 {
return nil
}
m := findByMessageID(hs[0])
_, m := findByMessageID(hs[0])
messageInputField.SetTitle("Replying to " + m.Author.String())
app.SetFocus(messageInputField)
return nil
@ -194,7 +209,7 @@ func onMessagesViewInputCapture(e *tcell.EventKey) *tcell.EventKey {
return nil
}
m := findByMessageID(hs[0])
_, m := findByMessageID(hs[0])
messageInputField.SetTitle("[@] Replying to " + m.Author.String())
app.SetFocus(messageInputField)
return nil
@ -204,7 +219,7 @@ func onMessagesViewInputCapture(e *tcell.EventKey) *tcell.EventKey {
return nil
}
m := findByMessageID(hs[0])
_, m := findByMessageID(hs[0])
err := clipboard.WriteAll(m.Content)
if err != nil {
return nil

View file

@ -27,14 +27,14 @@ func generateChannelRepr(c *discordgo.Channel) string {
return repr
}
func findByMessageID(mID string) *discordgo.Message {
for _, m := range selectedChannel.Messages {
func findByMessageID(mID string) (int, *discordgo.Message) {
for i, m := range selectedChannel.Messages {
if m.ID == mID {
return m
return i, m
}
}
return nil
return -1, nil
}
func createPrivateChannels(n *tview.TreeNode) {