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() {
case views.CHANNELS:
c.views.SetPrevious(view)
_, cy := v.Cursor()
err := c.models.SetCurrentChannel(context.Background(), cy)
index := c.views.Channels.Index()
err := c.models.SetCurrentChannel(context.Background(), index)
if err != nil {
return err
}

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

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

Loading…
Cancel
Save