From 76a9ff1dae389d2d69554b8de860eb2ec241c2ad Mon Sep 17 00:00:00 2001 From: ayntgl <90600421+ayntgl@users.noreply.github.com> Date: Wed, 15 Sep 2021 23:25:56 +0400 Subject: [PATCH] fix: return if there are no selected channel messages (#44) --- discordo.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/discordo.go b/discordo.go index 32d02b9..0ba6da6 100644 --- a/discordo.go +++ b/discordo.go @@ -111,6 +111,10 @@ func onMessagesWidgetInputCapture(e *tcell.EventKey) *tcell.EventKey { switch { case e.Key() == tcell.KeyUp || e.Rune() == 'k': // Up ms := selectedChannel.Messages + if len(ms) == 0 { + return nil + } + hs := messagesWidget.GetHighlights() // If there are no currently highlighted message, highlight the last // message in the TextView. @@ -138,6 +142,10 @@ func onMessagesWidgetInputCapture(e *tcell.EventKey) *tcell.EventKey { return nil case e.Key() == tcell.KeyDown || e.Rune() == 'j': // Down ms := selectedChannel.Messages + if len(ms) == 0 { + return nil + } + hs := messagesWidget.GetHighlights() // If there are no currently highlighted message, highlight the last // message in the TextView. @@ -165,6 +173,10 @@ func onMessagesWidgetInputCapture(e *tcell.EventKey) *tcell.EventKey { return nil case e.Key() == tcell.KeyHome || e.Rune() == 'g': // Top ms := selectedChannel.Messages + if len(ms) == 0 { + return nil + } + // Highlight the last message in the selectedChannel.Messages slice // (the first message rendered in the TextView). messagesWidget. @@ -172,6 +184,10 @@ func onMessagesWidgetInputCapture(e *tcell.EventKey) *tcell.EventKey { ScrollToHighlight() case e.Key() == tcell.KeyEnd || e.Rune() == 'G': // Bottom ms := selectedChannel.Messages + if len(ms) == 0 { + return nil + } + // Highlight the first message in the selectedChannel.Messages slice // (the last message rendered in the TextView). messagesWidget. @@ -179,6 +195,10 @@ func onMessagesWidgetInputCapture(e *tcell.EventKey) *tcell.EventKey { ScrollToHighlight() case e.Rune() == 'r': // Reply ms := selectedChannel.Messages + if len(ms) == 0 { + return nil + } + hs := messagesWidget.GetHighlights() if len(hs) == 0 { return nil