parent
bc11d9891a
commit
3b88e203ff
@ -321,17 +321,14 @@ func (c *Channels) Search(term string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(c.SearchMatches) > 0 {
|
if len(c.SearchMatches) > 0 {
|
||||||
c.GotoPosition(0)
|
c.GotoPositionSearch(0)
|
||||||
c.SearchPosition = 0
|
c.SearchPosition = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GotoPosition is used by the search functionality to automatically
|
// GotoPosition is used by to automatically scroll to a specific
|
||||||
// scroll to a specific location in the channels component
|
// location in the channels component
|
||||||
func (c *Channels) GotoPosition(position int) {
|
func (c *Channels) GotoPosition(newPos int) {
|
||||||
|
|
||||||
// The new position
|
|
||||||
newPos := c.SearchMatches[position]
|
|
||||||
|
|
||||||
// Is the new position in range of the current view?
|
// Is the new position in range of the current view?
|
||||||
minRange := c.Offset
|
minRange := c.Offset
|
||||||
@ -358,11 +355,18 @@ func (c *Channels) GotoPosition(position int) {
|
|||||||
c.CursorPosition = (newPos - c.Offset) + 1
|
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
|
// SearchNext allows us to cycle through the c.SearchMatches
|
||||||
func (c *Channels) SearchNext() {
|
func (c *Channels) SearchNext() {
|
||||||
newPosition := c.SearchPosition + 1
|
newPosition := c.SearchPosition + 1
|
||||||
if newPosition <= len(c.SearchMatches)-1 {
|
if newPosition <= len(c.SearchMatches)-1 {
|
||||||
c.GotoPosition(newPosition)
|
c.GotoPositionSearch(newPosition)
|
||||||
c.SearchPosition = newPosition
|
c.SearchPosition = newPosition
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -371,7 +375,17 @@ func (c *Channels) SearchNext() {
|
|||||||
func (c *Channels) SearchPrev() {
|
func (c *Channels) SearchPrev() {
|
||||||
newPosition := c.SearchPosition - 1
|
newPosition := c.SearchPosition - 1
|
||||||
if newPosition >= 0 {
|
if newPosition >= 0 {
|
||||||
c.GotoPosition(newPosition)
|
c.GotoPositionSearch(newPosition)
|
||||||
c.SearchPosition = 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -87,6 +87,7 @@ func getDefaultConfig() Config {
|
|||||||
"C-d": "chat-down",
|
"C-d": "chat-down",
|
||||||
"n": "channel-search-next",
|
"n": "channel-search-next",
|
||||||
"N": "channel-search-prev",
|
"N": "channel-search-prev",
|
||||||
|
"'": "channel-jump",
|
||||||
"q": "quit",
|
"q": "quit",
|
||||||
"<f1>": "help",
|
"<f1>": "help",
|
||||||
},
|
},
|
||||||
|
@ -44,6 +44,7 @@ var actionMap = map[string]func(*context.AppContext){
|
|||||||
"channel-bottom": actionMoveCursorBottomChannels,
|
"channel-bottom": actionMoveCursorBottomChannels,
|
||||||
"channel-search-next": actionSearchNextChannels,
|
"channel-search-next": actionSearchNextChannels,
|
||||||
"channel-search-prev": actionSearchPrevChannels,
|
"channel-search-prev": actionSearchPrevChannels,
|
||||||
|
"channel-jump": actionJumpChannels,
|
||||||
"chat-up": actionScrollUpChat,
|
"chat-up": actionScrollUpChat,
|
||||||
"chat-down": actionScrollDownChat,
|
"chat-down": actionScrollDownChat,
|
||||||
"help": actionHelp,
|
"help": actionHelp,
|
||||||
@ -406,6 +407,11 @@ func actionSearchPrevChannels(ctx *context.AppContext) {
|
|||||||
actionChangeChannel(ctx)
|
actionChangeChannel(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func actionJumpChannels(ctx *context.AppContext) {
|
||||||
|
ctx.View.Channels.Jump()
|
||||||
|
actionChangeChannel(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func actionChangeChannel(ctx *context.AppContext) {
|
func actionChangeChannel(ctx *context.AppContext) {
|
||||||
// Clear messages from Chat pane
|
// Clear messages from Chat pane
|
||||||
ctx.View.Chat.ClearMessages()
|
ctx.View.Chat.ClearMessages()
|
||||||
|
Loading…
Reference in New Issue
Block a user