Add GrDiffCursor.moveToLastChunk

The new method is analogous to GrDiffCursor.moveToFirstChunk, and can be used
when navigating backwards through diffs.

Change-Id: I0c53c3247d4b996fe0dcc0df65e5497494d7c9e7
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.js b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.js
index 05a7525..726ac10 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.js
@@ -237,6 +237,11 @@
       this.moveToNextChunk(true);
     }
 
+    moveToLastChunk() {
+      this.$.cursorManager.moveToEnd();
+      this.moveToPreviousChunk();
+    }
+
     reInitCursor() {
       this._updateStops();
       if (this.initialLineNumber) {
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor_test.html b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor_test.html
index dff9e79..24ca3d1 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor_test.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor_test.html
@@ -108,6 +108,18 @@
       assert.equal(cursorElement.diffRow, firstDeltaRow);
     });
 
+    test('moveToLastChunk', () => {
+      const chunks = Array.from(Polymer.dom(diffElement.root).querySelectorAll(
+          '.section.delta'));
+      assert.isAbove(chunks.length, 1);
+      assert.equal(chunks.indexOf(cursorElement.diffRow.parentElement), 0);
+
+      cursorElement.moveToLastChunk();
+
+      assert.equal(chunks.indexOf(cursorElement.diffRow.parentElement),
+          chunks.length - 1);
+    });
+
     test('cursor scroll behavior', () => {
       cursorElement._handleDiffRenderStart();
       assert.equal(cursorElement._scrollBehavior, 'keep-visible');
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 374204b..fd70fd9 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
@@ -163,6 +163,12 @@
       }
     }
 
+    moveToEnd() {
+      if (this.stops.length) {
+        this.setCursor(this.stops[this.stops.length - 1]);
+      }
+    }
+
     setCursorAtIndex(index, opt_noScroll) {
       this.setCursor(this.stops[index], opt_noScroll);
     }