Merge "If file is unchanged, start scrolled to top"
This commit is contained in:
@@ -136,11 +136,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
moveToNextChunk() {
|
moveToNextChunk(opt_clipToTop) {
|
||||||
this.$.cursorManager.next(this._isFirstRowOfChunk.bind(this),
|
this.$.cursorManager.next(this._isFirstRowOfChunk.bind(this),
|
||||||
target => {
|
target => {
|
||||||
return target.parentNode.scrollHeight;
|
return target.parentNode.scrollHeight;
|
||||||
});
|
}, opt_clipToTop);
|
||||||
this._fixSide();
|
this._fixSide();
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -200,7 +200,7 @@
|
|||||||
|
|
||||||
moveToFirstChunk() {
|
moveToFirstChunk() {
|
||||||
this.$.cursorManager.moveToStart();
|
this.$.cursorManager.moveToStart();
|
||||||
this.moveToNextChunk();
|
this.moveToNextChunk(true);
|
||||||
},
|
},
|
||||||
|
|
||||||
reInitCursor() {
|
reInitCursor() {
|
||||||
|
@@ -90,8 +90,21 @@
|
|||||||
this.unsetCursor();
|
this.unsetCursor();
|
||||||
},
|
},
|
||||||
|
|
||||||
next(opt_condition, opt_getTargetHeight) {
|
/**
|
||||||
this._moveCursor(1, opt_condition, opt_getTargetHeight);
|
* Move the cursor forward. Clipped to the ends of the stop list.
|
||||||
|
* @param {!Function=} opt_condition Optional stop condition. If a condition
|
||||||
|
* is passed the cursor will continue to move in the specified direction
|
||||||
|
* until the condition is met.
|
||||||
|
* @param {!Function=} opt_getTargetHeight Optional function to calculate the
|
||||||
|
* height of the target's 'section'. The height of the target itself is
|
||||||
|
* sometimes different, used by the diff cursor.
|
||||||
|
* @param {boolean=} opt_clipToTop When none of the next indices match, move
|
||||||
|
* back to first instead of to last.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
|
||||||
|
next(opt_condition, opt_getTargetHeight, opt_clipToTop) {
|
||||||
|
this._moveCursor(1, opt_condition, opt_getTargetHeight, opt_clipToTop);
|
||||||
},
|
},
|
||||||
|
|
||||||
previous(opt_condition) {
|
previous(opt_condition) {
|
||||||
@@ -145,8 +158,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the cursor forward or backward by delta. Noop if moving past either
|
* Move the cursor forward or backward by delta. Clipped to the beginning or
|
||||||
* end of the stop list.
|
* end of stop list.
|
||||||
* @param {number} delta either -1 or 1.
|
* @param {number} delta either -1 or 1.
|
||||||
* @param {!Function=} opt_condition Optional stop condition. If a condition
|
* @param {!Function=} opt_condition Optional stop condition. If a condition
|
||||||
* is passed the cursor will continue to move in the specified direction
|
* is passed the cursor will continue to move in the specified direction
|
||||||
@@ -154,9 +167,11 @@
|
|||||||
* @param {!Function=} opt_getTargetHeight Optional function to calculate the
|
* @param {!Function=} opt_getTargetHeight Optional function to calculate the
|
||||||
* height of the target's 'section'. The height of the target itself is
|
* height of the target's 'section'. The height of the target itself is
|
||||||
* sometimes different, used by the diff cursor.
|
* sometimes different, used by the diff cursor.
|
||||||
|
* @param {boolean=} opt_clipToTop When none of the next indices match, move
|
||||||
|
* back to first instead of to last.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_moveCursor(delta, opt_condition, opt_getTargetHeight) {
|
_moveCursor(delta, opt_condition, opt_getTargetHeight, opt_clipToTop) {
|
||||||
if (!this.stops.length) {
|
if (!this.stops.length) {
|
||||||
this.unsetCursor();
|
this.unsetCursor();
|
||||||
return;
|
return;
|
||||||
@@ -164,7 +179,7 @@
|
|||||||
|
|
||||||
this._unDecorateTarget();
|
this._unDecorateTarget();
|
||||||
|
|
||||||
const newIndex = this._getNextindex(delta, opt_condition);
|
const newIndex = this._getNextindex(delta, opt_condition, opt_clipToTop);
|
||||||
|
|
||||||
let newTarget = null;
|
let newTarget = null;
|
||||||
if (newIndex !== -1) {
|
if (newIndex !== -1) {
|
||||||
@@ -203,10 +218,12 @@
|
|||||||
* Get the next stop index indicated by the delta direction.
|
* Get the next stop index indicated by the delta direction.
|
||||||
* @param {number} delta either -1 or 1.
|
* @param {number} delta either -1 or 1.
|
||||||
* @param {!Function=} opt_condition Optional stop condition.
|
* @param {!Function=} opt_condition Optional stop condition.
|
||||||
|
* @param {boolean=} opt_clipToTop When none of the next indices match, move
|
||||||
|
* back to first instead of to last.
|
||||||
* @return {number} the new index.
|
* @return {number} the new index.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_getNextindex(delta, opt_condition) {
|
_getNextindex(delta, opt_condition, opt_clipToTop) {
|
||||||
if (!this.stops.length || this.index === -1) {
|
if (!this.stops.length || this.index === -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -222,10 +239,10 @@
|
|||||||
|
|
||||||
// If we failed to satisfy the condition:
|
// If we failed to satisfy the condition:
|
||||||
if (opt_condition && !opt_condition(this.stops[newIndex])) {
|
if (opt_condition && !opt_condition(this.stops[newIndex])) {
|
||||||
if (delta > 0) {
|
if (delta < 0 || opt_clipToTop) {
|
||||||
return this.stops.length - 1;
|
|
||||||
} else if (delta < 0) {
|
|
||||||
return 0;
|
return 0;
|
||||||
|
} else if (delta > 0) {
|
||||||
|
return this.stops.length - 1;
|
||||||
}
|
}
|
||||||
return this.index;
|
return this.index;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user