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 05a7525bb5..726ac10bed 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 dff9e79ab5..24ca3d1502 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 @@ limitations under the License. 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 374204b603..fd70fd97a7 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); }