Add GrDiffCursor.moveToLastChunk

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

Change-Id: I0c53c3247d4b996fe0dcc0df65e5497494d7c9e7
This commit is contained in:
Mayank Kumar
2020-01-23 20:51:01 -08:00
parent 1b8cc9e9f2
commit ecbe22aeef
3 changed files with 23 additions and 0 deletions

View File

@@ -237,6 +237,11 @@
this.moveToNextChunk(true);
}
moveToLastChunk() {
this.$.cursorManager.moveToEnd();
this.moveToPreviousChunk();
}
reInitCursor() {
this._updateStops();
if (this.initialLineNumber) {

View File

@@ -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');

View File

@@ -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);
}