Fix conditional cursor iteration

It's okay to keep going when at the first element if we go forward, and
when at the last element if we are going backwards.

Change-Id: Ibf06b8b2133b3436e44fc687c6a52159637cae3b
diff --git a/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.js b/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.js
index 37c3d52..222109e 100644
--- a/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.js
+++ b/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.js
@@ -337,8 +337,8 @@
     }
     do {
       newIndex = newIndex + delta;
-    } while (newIndex > 0 &&
-             newIndex < this.stops.length - 1 &&
+    } while ((delta > 0 || newIndex > 0) &&
+             (delta < 0 || newIndex < this.stops.length - 1) &&
              opt_condition && !opt_condition(this.stops[newIndex]));
 
     newIndex = Math.max(0, Math.min(this.stops.length - 1, newIndex));