From 86d4752e0eda6d1815a5d3c2ff4e34dfb9ab6cce Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Fri, 2 Dec 2016 08:45:46 +0100 Subject: [PATCH] PolyGerrit: Add next/previous page key binding Bug: Issue 4259 Change-Id: I0f8c4f552e0629269d6994921be156b6a322635b --- .../gr-change-list-view.js | 17 +++++++++++ .../gr-change-list/gr-change-list.js | 28 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.js b/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.js index 45d9a57fe5..38b1db6ade 100644 --- a/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.js +++ b/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view.js @@ -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)); + }, }); })(); diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js index fdff7cd526..eaa85279aa 100644 --- a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js +++ b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js @@ -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]) {