From 50aa0f95587b7c96134e535ec2989aade9164f0f Mon Sep 17 00:00:00 2001
From: "James E. Blair" <jeblair@hp.com>
Date: Sat, 23 May 2015 15:46:02 -0700
Subject: [PATCH] Advance cursor on change list toggle

When toggling any flag on a row in the change list, advance the
cursor to the next row.

Change-Id: I0d140748a1bccf97d3c3b9b132d76947caa6f820
---
 gertty/view/change_list.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/gertty/view/change_list.py b/gertty/view/change_list.py
index 952777b..39114c2 100644
--- a/gertty/view/change_list.py
+++ b/gertty/view/change_list.py
@@ -408,6 +408,12 @@ class ChangeListView(urwid.WidgetWrap):
             self.log.debug("Set change %s to %s", change_key, hidden_str)
         return ret
 
+    def advance(self):
+        pos = self.listbox.focus_position
+        if pos < len(self.listbox.body)-1:
+            pos += 1
+            self.listbox.focus_position = pos
+
     def keypress(self, size, key):
         r = super(ChangeListView, self).keypress(size, key)
         commands = self.app.config.keymap.getCommands(r)
@@ -433,6 +439,7 @@ class ChangeListView(urwid.WidgetWrap):
                 # where we're not just popping a row from the list of unreviewed
                 # changes.
                 self.refresh()
+                self.advance()
             return None
         if keymap.TOGGLE_HIDDEN in commands:
             if not len(self.listbox.body):
@@ -450,6 +457,7 @@ class ChangeListView(urwid.WidgetWrap):
                 # Just fall back on doing a full refresh if we're in a situation
                 # where we're not just popping a row from the list of changes.
                 self.refresh()
+                self.advance()
             return None
         if keymap.TOGGLE_HELD in commands:
             if not len(self.listbox.body):
@@ -461,6 +469,7 @@ class ChangeListView(urwid.WidgetWrap):
             with self.app.db.getSession() as session:
                 change = session.getChange(change_key)
                 row.update(change, self.categories)
+            self.advance()
             return None
         if keymap.TOGGLE_STARRED in commands:
             if not len(self.listbox.body):
@@ -472,6 +481,7 @@ class ChangeListView(urwid.WidgetWrap):
             with self.app.db.getSession() as session:
                 change = session.getChange(change_key)
                 row.update(change, self.categories)
+            self.advance()
             return None
         if keymap.TOGGLE_MARK in commands:
             if not len(self.listbox.body):
@@ -483,9 +493,7 @@ class ChangeListView(urwid.WidgetWrap):
             with self.app.db.getSession() as session:
                 change = session.getChange(change_key)
                 row.update(change, self.categories)
-            if pos < len(self.listbox.body)-1:
-                pos += 1
-                self.listbox.focus_position = pos
+            self.advance()
             return None
         if keymap.REFRESH in commands:
             if self.project_key: