~chrisppy/beagles

7f9276be6300e69b1ba72d9fb0cdf7f7a6877a21 — Chris Palmer 23 days ago 950d286
Fix up/down navigation errors when list/tree is empty
2 files changed, 52 insertions(+), 0 deletions(-)

M ui/navigation.go
M ui/tree.go
M ui/navigation.go => ui/navigation.go +48 -0
@@ 66,18 66,30 @@ func (i *UI) moveUp(event *tcell.EventKey) *tcell.EventKey {

	switch i.status {
	case listStatus:
		if i.list.size() == 0 {
			return nil
		}

		key := i.list.decrement()
		if key != "" {
			i.content.setText(i.DB.Items[key])
		}
		return nil
	case favStatus:
		if i.favList.size() == 0 {
			return nil
		}

		key := i.favList.decrement()
		if key != "" {
			i.favContent.setText(i.DB.Items[key])
		}
		return nil
	case subStatus:
		if i.subTree.size() == 0 {
			return nil
		}

		key := i.subTree.decrement()
		if val, ok := i.DB.Feeds[key]; ok {
			i.subContent.setDescription(val.Description, true)


@@ 101,6 113,10 @@ func (i *UI) moveDown(event *tcell.EventKey) *tcell.EventKey {

	switch i.status {
	case listStatus:
		if i.list.size() == 0 {
			return nil
		}

		key := i.list.increment()
		if key != "" {
			i.content.setText(i.DB.Items[key])


@@ 108,6 124,10 @@ func (i *UI) moveDown(event *tcell.EventKey) *tcell.EventKey {

		return nil
	case favStatus:
		if i.favList.size() == 0 {
			return nil
		}

		key := i.favList.increment()
		if key != "" {
			i.favContent.setText(i.DB.Items[key])


@@ 115,6 135,10 @@ func (i *UI) moveDown(event *tcell.EventKey) *tcell.EventKey {

		return nil
	case subStatus:
		if i.subTree.size() == 0 {
			return nil
		}

		key := i.subTree.increment()
		if val, ok := i.DB.Feeds[key]; ok {
			i.subContent.setDescription(val.Description, true)


@@ 138,18 162,30 @@ func (i *UI) movePageUp(event *tcell.EventKey) *tcell.EventKey {

	switch i.status {
	case listStatus:
		if i.list.size() == 0 {
			return nil
		}

		key := i.list.pageUp()
		if key != "" {
			i.content.setText(i.DB.Items[key])
		}
		return nil
	case favStatus:
		if i.favList.size() == 0 {
			return nil
		}

		key := i.favList.pageUp()
		if key != "" {
			i.favContent.setText(i.DB.Items[key])
		}
		return nil
	case subStatus:
		if i.subTree.size() == 0 {
			return nil
		}

		key := i.subTree.pageUp()
		if val, ok := i.DB.Feeds[key]; ok {
			i.subContent.setDescription(val.Description, true)


@@ 173,18 209,30 @@ func (i *UI) movePageDown(event *tcell.EventKey) *tcell.EventKey {

	switch i.status {
	case listStatus:
		if i.list.size() == 0 {
			return nil
		}

		key := i.list.pageDown()
		if key != "" {
			i.content.setText(i.DB.Items[key])
		}
		return nil
	case favStatus:
		if i.favList.size() == 0 {
			return nil
		}

		key := i.favList.pageDown()
		if key != "" {
			i.favContent.setText(i.DB.Items[key])
		}
		return nil
	case subStatus:
		if i.subTree.size() == 0 {
			return nil
		}

		key := i.subTree.pageDown()
		if val, ok := i.DB.Feeds[key]; ok {
			i.subContent.setDescription(val.Description, true)

M ui/tree.go => ui/tree.go +4 -0
@@ 172,6 172,10 @@ func getTitle(title string, unread int, increment bool, decrement bool) string {
	return fmt.Sprintf("%s (*%d)", title, digit)
}

func (w *tree) size() int {
	return len(w.ChildNodes)
}

func (w *tree) getKey() string {
	n := w.Widget.GetCurrentNode()