Implement the 'a' keyboard shortcut in the diff view

This allows a user to quickly jump to publishing comments in the
change view from the diff view.

Bug: Issue 3840
Change-Id: Idec29646cd3fcabea23df7935ee8c7e5effa1135
This commit is contained in:
Andrew Bonventre
2016-01-28 14:58:04 -05:00
parent cae9bd1423
commit 349380e121
3 changed files with 45 additions and 4 deletions

View File

@@ -400,14 +400,24 @@ limitations under the License.
}
this._reload().then(function() {
this.$.messageList.topMargin = this._headerEl.offsetHeight;
// Allow the message list to render before scrolling.
this.async(function() {
var prefix = '#message-';
if (window.location.hash.indexOf(prefix) == 0) {
this.$.messageList.scrollToMessage(
window.location.hash.substr(prefix.length));
var msgPrefix = '#message-';
var hash = window.location.hash;
if (hash.indexOf(msgPrefix) == 0) {
this.$.messageList.scrollToMessage(hash.substr(msgPrefix.length));
}
}.bind(this), 1);
app.accountReady.then(function() {
if (!this._loggedIn) { return; }
if (window.sessionStorage.getItem('changeView.showReplyDropdown')) {
this.$.replyDropdown.open();
window.sessionStorage.removeItem('changeView.showReplyDropdown');
}
}.bind(this));
}.bind(this));
},

View File

@@ -168,6 +168,16 @@ limitations under the License.
type: Function,
value: function() { return this._handleKey.bind(this); },
},
_loggedIn: {
type: Boolean,
value: false,
},
},
ready: function() {
app.accountReady.then(function() {
this._loggedIn = app.loggedIn;
}.bind(this));
},
attached: function() {
@@ -193,6 +203,13 @@ limitations under the License.
e.preventDefault();
this._navToFile(this._fileList, 1);
break;
case 65: // 'a'
if (!this._loggedIn) { return; }
// Values can only be strings.
window.sessionStorage.setItem(
'changeView.showReplyDropdown', 'true');
// No break here. Allow to fall through.
case 85: // 'u'
if (this._changeNum) {
e.preventDefault();

View File

@@ -97,6 +97,20 @@ limitations under the License.
var showStub = sinon.stub(page, 'show');
MockInteractions.pressAndReleaseKeyOn(element, 65); // 'a'
assert.isTrue(showStub.notCalled, 'The `a` keyboard shortcut should ' +
'only work when the user is logged in.');
assert.isNull(window.sessionStorage.getItem(
'changeView.showReplyDropdown'));
element._loggedIn = true;
MockInteractions.pressAndReleaseKeyOn(element, 65); // 'a'
assert.equal(window.sessionStorage.getItem(
'changeView.showReplyDropdown'), 'true');
window.sessionStorage.removeItem('changeView.showReplyDropdown');
assert(showStub.lastCall.calledWithExactly('/c/42'),
'Should navigate to /c/42');
MockInteractions.pressAndReleaseKeyOn(element, 85); // 'u'
assert(showStub.lastCall.calledWithExactly('/c/42'),
'Should navigate to /c/42');