Merge "PolyGerrit: Add next/previous page key binding"

This commit is contained in:
Saša Živkov
2017-01-20 14:38:31 +00:00
committed by Gerrit Code Review
2 changed files with 45 additions and 0 deletions

View File

@@ -76,6 +76,11 @@
},
},
listeners: {
'next-page': '_handleNextPage',
'previous-page': '_handlePreviousPage',
},
attached: function() {
this.fire('title-change', {title: this._query});
},
@@ -132,5 +137,17 @@
_hideNextArrow: function(loading, changesPerPage) {
return loading || !this._changes || this._changes.length < changesPerPage;
},
_handleNextPage() {
if (this._hideNextArrow(this._offset)) { return; }
page.show(this._computeNavLink(
this._query, this._offset, 1, this._changesPerPage));
},
_handlePreviousPage() {
if (this._hidePrevArrow(this._offset)) { return; }
page.show(this._computeNavLink(
this._query, this._offset, -1, this._changesPerPage));
},
});
})();

View File

@@ -17,6 +17,18 @@
Polymer({
is: 'gr-change-list',
/**
* Fired when next page key shortcut was pressed.
*
* @event next-page
*/
/**
* Fired when previous page key shortcut was pressed.
*
* @event previous-page
*/
hostAttributes: {
tabindex: 0,
},
@@ -82,7 +94,9 @@
keyBindings: {
'j': '_handleJKey',
'k': '_handleKKey',
'n ]': '_handleNKey',
'o enter': '_handleEnterKey',
'p [': '_handlePKey',
},
attached: function() {
@@ -206,6 +220,20 @@
page.show(this._changeURLForIndex(this.selectedIndex));
},
_handleNKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
e.preventDefault();
this.fire('next-page');
},
_handlePKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
e.preventDefault();
this.fire('previous-page');
},
_changeURLForIndex: function(index) {
var changeEls = this._getListItems();
if (index < changeEls.length && changeEls[index]) {