fix: return if there are no selected channel messages (#44)

This commit is contained in:
ayntgl 2021-09-15 23:25:56 +04:00 • committed by GitHub
parent cfbee6c2f1
commit 76a9ff1dae

View file

@ -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