diff --git a/components/channels.go b/components/channels.go index 498822c..3dbbce2 100644 --- a/components/channels.go +++ b/components/channels.go @@ -321,17 +321,14 @@ func (c *Channels) Search(term string) { } if len(c.SearchMatches) > 0 { - c.GotoPosition(0) + c.GotoPositionSearch(0) c.SearchPosition = 0 } } -// GotoPosition is used by the search functionality to automatically -// scroll to a specific location in the channels component -func (c *Channels) GotoPosition(position int) { - - // The new position - newPos := c.SearchMatches[position] +// GotoPosition is used by to automatically scroll to a specific +// location in the channels component +func (c *Channels) GotoPosition(newPos int) { // Is the new position in range of the current view? minRange := c.Offset @@ -358,11 +355,18 @@ func (c *Channels) GotoPosition(position int) { c.CursorPosition = (newPos - c.Offset) + 1 } +// GotoPosition is used by the search functionality to automatically +// scroll to a specific location in the channels component +func (c *Channels) GotoPositionSearch(position int) { + newPos := c.SearchMatches[position] + c.GotoPosition(newPos) +} + // SearchNext allows us to cycle through the c.SearchMatches func (c *Channels) SearchNext() { newPosition := c.SearchPosition + 1 if newPosition <= len(c.SearchMatches)-1 { - c.GotoPosition(newPosition) + c.GotoPositionSearch(newPosition) c.SearchPosition = newPosition } } @@ -371,7 +375,17 @@ func (c *Channels) SearchNext() { func (c *Channels) SearchPrev() { newPosition := c.SearchPosition - 1 if newPosition >= 0 { - c.GotoPosition(newPosition) + c.GotoPositionSearch(newPosition) c.SearchPosition = newPosition } } + +// Jump to the first channel with a notification +func (c *Channels) Jump() { + for i, channel := range c.ChannelItems { + if channel.Notification { + c.GotoPosition(i) + break + } + } +} diff --git a/config/config.go b/config/config.go index 8d0b775..aa378d0 100644 --- a/config/config.go +++ b/config/config.go @@ -87,6 +87,7 @@ func getDefaultConfig() Config { "C-d": "chat-down", "n": "channel-search-next", "N": "channel-search-prev", + "'": "channel-jump", "q": "quit", "": "help", }, diff --git a/handlers/event.go b/handlers/event.go index ac705d0..c142fc4 100644 --- a/handlers/event.go +++ b/handlers/event.go @@ -44,6 +44,7 @@ var actionMap = map[string]func(*context.AppContext){ "channel-bottom": actionMoveCursorBottomChannels, "channel-search-next": actionSearchNextChannels, "channel-search-prev": actionSearchPrevChannels, + "channel-jump": actionJumpChannels, "chat-up": actionScrollUpChat, "chat-down": actionScrollDownChat, "help": actionHelp, @@ -406,6 +407,11 @@ func actionSearchPrevChannels(ctx *context.AppContext) { actionChangeChannel(ctx) } +func actionJumpChannels(ctx *context.AppContext) { + ctx.View.Channels.Jump() + actionChangeChannel(ctx) +} + func actionChangeChannel(ctx *context.AppContext) { // Clear messages from Chat pane ctx.View.Chat.ClearMessages()