From 7cf779f5212d120cbefae47ae75d9c1e2e84492f Mon Sep 17 00:00:00 2001 From: cyberme0w Date: Tue, 12 Mar 2024 09:23:25 +0000 Subject: [PATCH] Unselect messages after last one (#352) --- cmd/messages_text.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/cmd/messages_text.go b/cmd/messages_text.go index 291f5e0..52ae740 100644 --- a/cmd/messages_text.go +++ b/cmd/messages_text.go @@ -221,19 +221,20 @@ func (mt *MessagesText) selectNextAction() { return } - // If no message is currently selected, select the latest message. - if len(mt.GetHighlights()) == 0 { - mt.selectedMessage = 0 - } else { - if mt.selectedMessage > 0 { - mt.selectedMessage-- - } else { - return - } - } + // If no message is currently selected, do nothing + if mt.selectedMessage == -1 { return } - mt.Highlight(ms[mt.selectedMessage].ID.String()) - mt.ScrollToHighlight() + // Otherwise select the next message. This causes the desired + // behaviour of unselecting messages after the last one. + mt.selectedMessage-- + + // If a message is selected, highlight it and scroll to it, otherwise remove the highlight + if mt.selectedMessage >= 0 { + mt.Highlight(ms[mt.selectedMessage].ID.String()) + mt.ScrollToHighlight() + } else { + mt.Highlight() + } } func (mt *MessagesText) selectFirstAction() {