Merge "Add keyboard shortcuts for expanding and collapsing all messages"

This commit is contained in:
Wyatt Allen
2017-01-09 22:27:54 +00:00
committed by Gerrit Code Review
4 changed files with 66 additions and 4 deletions

View File

@@ -129,6 +129,8 @@
'd': '_handleDKey', 'd': '_handleDKey',
's': '_handleSKey', 's': '_handleSKey',
'u': '_handleUKey', 'u': '_handleUKey',
'x': '_handleXKey',
'z': '_handleZKey',
}, },
attached: function() { attached: function() {
@@ -652,6 +654,22 @@
this._determinePageBack(); this._determinePageBack();
}, },
_handleXKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this.$.messageList.handleExpandCollapse(true);
},
_handleZKey: function(e) {
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this.$.messageList.handleExpandCollapse(false);
},
_determinePageBack: function() { _determinePageBack: function() {
// Default backPage to '/' if user came to change view page // Default backPage to '/' if user came to change view page
// via an email link, etc. // via an email link, etc.

View File

@@ -85,6 +85,20 @@ limitations under the License.
assert.isFalse(overlayEl.opened); assert.isFalse(overlayEl.opened);
}); });
test('X should expand all messages', function() {
var handleExpand =
sandbox.stub(element.$.messageList, 'handleExpandCollapse');
MockInteractions.pressAndReleaseKeyOn(element, 88, null, 'x');
assert(handleExpand.calledWith(true));
});
test('Z should collapse all messages', function() {
var handleExpand =
sandbox.stub(element.$.messageList, 'handleExpandCollapse');
MockInteractions.pressAndReleaseKeyOn(element, 90, null, 'z');
assert(handleExpand.calledWith(false));
});
test('shift + R should fetch and navigate to the latest patch set', test('shift + R should fetch and navigate to the latest patch set',
function(done) { function(done) {
element._changeNum = '42'; element._changeNum = '42';

View File

@@ -106,15 +106,22 @@
el.classList.add('highlighted'); el.classList.add('highlighted');
}, },
_handleExpandCollapseTap: function(e) { /**
e.preventDefault(); * @param {boolean} expand
this._expanded = !this._expanded; */
handleExpandCollapse: function(expand) {
this._expanded = expand;
var messageEls = Polymer.dom(this.root).querySelectorAll('gr-message'); var messageEls = Polymer.dom(this.root).querySelectorAll('gr-message');
for (var i = 0; i < messageEls.length; i++) { for (var i = 0; i < messageEls.length; i++) {
messageEls[i].expanded = this._expanded; messageEls[i].expanded = expand;
} }
}, },
_handleExpandCollapseTap: function(e) {
e.preventDefault();
this.handleExpandCollapse(!this._expanded);
},
_handleAutomatedMessageToggleTap: function(e) { _handleAutomatedMessageToggleTap: function(e) {
e.preventDefault(); e.preventDefault();
this._hideAutomated = !this._hideAutomated; this._hideAutomated = !this._hideAutomated;

View File

@@ -86,6 +86,29 @@ limitations under the License.
} }
}); });
test('expand/collapse from external keypress', function() {
element.handleExpandCollapse(true);
var allMessageEls =
Polymer.dom(element.root).querySelectorAll('gr-message');
for (var i = 0; i < allMessageEls.length; i++) {
assert.isTrue(allMessageEls[i].expanded);
}
// Expand/collapse all text also changes.
assert.equal(element.$$('#collapse-messages').textContent.trim(),
'Collapse all');
element.handleExpandCollapse(false);
var allMessageEls =
Polymer.dom(element.root).querySelectorAll('gr-message');
for (var i = 0; i < allMessageEls.length; i++) {
assert.isFalse(allMessageEls[i].expanded);
}
// Expand/collapse all text also changes.
assert.equal(element.$$('#collapse-messages').textContent.trim(),
'Expand all');
});
test('hide messages does not appear when no automated messages', test('hide messages does not appear when no automated messages',
function() { function() {
assert.isOk(element.$$('#automatedMessageToggleContainer[hidden]')); assert.isOk(element.$$('#automatedMessageToggleContainer[hidden]'));