Add channel scroll top and bottom

Fixes #20
This commit is contained in:
erroneousboat 2016-10-18 21:11:29 +02:00
parent c1fc94a124
commit b46f7c491e
3 changed files with 58 additions and 20 deletions

View File

@ -43,10 +43,12 @@ Usage
-----
| mode | key | action |
|--------|-----------|--------------------------|
|--------|-----------|----------------------------|
| normal | `i` | insert mode |
| normal | `k` | move channel cursor up |
| normal | `j` | move channel cursor down |
| normal | `gg` | move channel cursor top |
| normal | `G` | move channel cursor bottom |
| normal | `pg-up` | scroll chat pane up |
| normal | `ctrl-b` | scroll chat pane up |
| normal | `ctrl-u` | scroll chat pane up |

View File

@ -12,9 +12,9 @@ import (
// Channels is the definition of a Channels component
type Channels struct {
List *termui.List
SelectedChannel int
Offset int
CursorPosition int
SelectedChannel int // index of which channel is selected from the List
Offset int // from what offset are channels rendered
CursorPosition int // the y position of the 'cursor'
}
// CreateChannels is the constructor for the Channels component
@ -142,6 +142,28 @@ func (c *Channels) MoveCursorDown() {
}
}
// MoveCursorTop will move the cursor to the top of the channels
func (c *Channels) MoveCursorTop() {
c.SetSelectedChannel(0)
c.CursorPosition = c.List.InnerBounds().Min.Y
c.Offset = 0
}
// MoveCursorBottom will move the cursor to the bottom of the channels
func (c *Channels) MoveCursorBottom() {
c.SetSelectedChannel(len(c.List.Items) - 1)
offset := len(c.List.Items) - (c.List.InnerBounds().Max.Y - 1)
if offset < 0 {
c.Offset = 0
c.CursorPosition = c.SelectedChannel + 1
} else {
c.Offset = offset
c.CursorPosition = c.List.InnerBounds().Max.Y - 1
}
}
// ScrollUp enables us to scroll through the channel list when it overflows
func (c *Channels) ScrollUp() {
if c.CursorPosition == c.List.InnerBounds().Min.Y {

View File

@ -43,6 +43,10 @@ func anyKeyHandler(ctx *context.AppContext) {
actionMoveCursorDownChannels(ctx)
case 'k':
actionMoveCursorUpChannels(ctx)
case 'g':
actionMoveCursorTopChannels(ctx)
case 'G':
actionMoveCursorBottomChannels(ctx)
case 'i':
actionInsertMode(ctx)
}
@ -208,6 +212,16 @@ func actionMoveCursorDownChannels(ctx *context.AppContext) {
actionChangeChannel(ctx)
}
func actionMoveCursorTopChannels(ctx *context.AppContext) {
ctx.View.Channels.MoveCursorTop()
actionChangeChannel(ctx)
}
func actionMoveCursorBottomChannels(ctx *context.AppContext) {
ctx.View.Channels.MoveCursorBottom()
actionChangeChannel(ctx)
}
func actionChangeChannel(ctx *context.AppContext) {
// Clear messages from Chat pane
ctx.View.Chat.ClearMessages()