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

@ -42,20 +42,22 @@ Getting started
Usage Usage
----- -----
| mode | key | action | | mode | key | action |
|--------|-----------|--------------------------| |--------|-----------|----------------------------|
| normal | `i` | insert mode | | normal | `i` | insert mode |
| normal | `k` | move channel cursor up | | normal | `k` | move channel cursor up |
| normal | `j` | move channel cursor down | | normal | `j` | move channel cursor down |
| normal | `pg-up` | scroll chat pane up | | normal | `gg` | move channel cursor top |
| normal | `ctrl-b` | scroll chat pane up | | normal | `G` | move channel cursor bottom |
| normal | `ctrl-u` | scroll chat pane up | | normal | `pg-up` | scroll chat pane up |
| normal | `pg-down` | scroll chat pane down | | normal | `ctrl-b` | scroll chat pane up |
| normal | `ctrl-f` | scroll chat pane down | | normal | `ctrl-u` | scroll chat pane up |
| normal | `ctrl-d` | scroll chat pane down | | normal | `pg-down` | scroll chat pane down |
| normal | `pg-down` | scroll chat pane down | | normal | `ctrl-f` | scroll chat pane down |
| normal | `q` | quit | | normal | `ctrl-d` | scroll chat pane down |
| insert | `left` | move input cursor left | | normal | `pg-down` | scroll chat pane down |
| insert | `right` | move input cursor right | | normal | `q` | quit |
| insert | `enter` | send message | | insert | `left` | move input cursor left |
| insert | `esc` | normal mode | | insert | `right` | move input cursor right |
| insert | `enter` | send message |
| insert | `esc` | normal mode |

View File

@ -12,9 +12,9 @@ import (
// Channels is the definition of a Channels component // Channels is the definition of a Channels component
type Channels struct { type Channels struct {
List *termui.List List *termui.List
SelectedChannel int SelectedChannel int // index of which channel is selected from the List
Offset int Offset int // from what offset are channels rendered
CursorPosition int CursorPosition int // the y position of the 'cursor'
} }
// CreateChannels is the constructor for the Channels component // 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 // ScrollUp enables us to scroll through the channel list when it overflows
func (c *Channels) ScrollUp() { func (c *Channels) ScrollUp() {
if c.CursorPosition == c.List.InnerBounds().Min.Y { if c.CursorPosition == c.List.InnerBounds().Min.Y {

View File

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