Short circuit file-list key handler when links are focused

Bug: Issue 5754
Change-Id: I65087be7aab102bf33915f0a438308cd84f6e97d
This commit is contained in:
Wyatt Allen
2017-03-10 16:30:36 -08:00
parent 68a23fcfb3
commit 2d5f8815a9
2 changed files with 42 additions and 0 deletions

View File

@@ -492,6 +492,10 @@
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
// Use native handling if an anchor is selected. @see Issue 5754
if (e.detail && e.detail.keyboardEvent && e.detail.keyboardEvent.target &&
e.detail.keyboardEvent.target.tagName === 'A') { return; }
e.preventDefault();
if (this._showInlineDiffs) {
this._openCursorFile();

View File

@@ -357,6 +357,44 @@ limitations under the License.
element.diffs[index].path);
}
});
test('_handleEnterKey navigates', function() {
sandbox.stub(element, 'shouldSuppressKeyboardShortcut').returns(false);
sandbox.stub(element, 'modifierPressed').returns(false);
var expandStub = sandbox.stub(element, '_openCursorFile');
var navStub = sandbox.stub(element, '_openSelectedFile');
var e = new CustomEvent('fake-keyboard-event');
sinon.stub(e, 'preventDefault');
element._showInlineDiffs = false;
element._handleEnterKey(e);
assert.isTrue(e.preventDefault.called);
assert.isTrue(navStub.called);
assert.isFalse(expandStub.called);
});
test('_handleEnterKey expands', function() {
sandbox.stub(element, 'shouldSuppressKeyboardShortcut').returns(false);
sandbox.stub(element, 'modifierPressed').returns(false);
var expandStub = sandbox.stub(element, '_openCursorFile');
var navStub = sandbox.stub(element, '_openSelectedFile');
var e = new CustomEvent('fake-keyboard-event');
sinon.stub(e, 'preventDefault');
element._showInlineDiffs = true;
element._handleEnterKey(e);
assert.isTrue(e.preventDefault.called);
assert.isFalse(navStub.called);
assert.isTrue(expandStub.called);
});
test('_handleEnterKey noop when anchor focused', function() {
sandbox.stub(element, 'shouldSuppressKeyboardShortcut').returns(false);
sandbox.stub(element, 'modifierPressed').returns(false);
var e = new CustomEvent('fake-keyboard-event',
{detail: {keyboardEvent: {target: document.createElement('a')}}});
sinon.stub(e, 'preventDefault');
element._handleEnterKey(e);
assert.isFalse(e.preventDefault.called);
});
});
test('comment filtering', function() {