fix view channels: wrong current channel

issue #11
pull/15/head
Edouard Paris 5 years ago
parent 392fc9676b
commit a4252ffdfb

@ -171,8 +171,8 @@ func (c *controller) OnEnter(g *gocui.Gui, v *gocui.View) error {
switch view.Name() { switch view.Name() {
case views.CHANNELS: case views.CHANNELS:
c.views.SetPrevious(view) c.views.SetPrevious(view)
_, cy := v.Cursor() index := c.views.Channels.Index()
err := c.models.SetCurrentChannel(context.Background(), cy) err := c.models.SetCurrentChannel(context.Background(), index)
if err != nil { if err != nil {
return err return err
} }

@ -16,6 +16,10 @@ func (c *Channels) List() []*models.Channel {
return c.list return c.list
} }
func (c *Channels) Len() int {
return len(c.list)
}
func (c *Channels) Get(index int) *models.Channel { func (c *Channels) Get(index int) *models.Channel {
if index < 0 || index > len(c.list)-1 { if index < 0 || index > len(c.list)-1 {
return nil return nil

@ -20,11 +20,16 @@ const (
) )
type Channels struct { type Channels struct {
index int
columns *gocui.View columns *gocui.View
view *gocui.View view *gocui.View
channels *models.Channels channels *models.Channels
} }
func (c Channels) Index() int {
return c.index
}
func (c Channels) Name() string { func (c Channels) Name() string {
return CHANNELS return CHANNELS
} }
@ -35,10 +40,17 @@ func (c *Channels) Wrap(v *gocui.View) view {
} }
func (c *Channels) CursorDown() error { func (c *Channels) CursorDown() error {
if c.channels.Len() <= c.index+1 {
return nil
}
c.index++
return cursorDown(c.view, 1) return cursorDown(c.view, 1)
} }
func (c *Channels) CursorUp() error { func (c *Channels) CursorUp() error {
if c.index > 0 {
c.index--
}
return cursorUp(c.view, 1) return cursorUp(c.view, 1)
} }

Loading…
Cancel
Save