Don't curse over files with up/down keys

Previously, if up/down keys were pressed, and the cursor was to move
over files rather than the diff rows, the file list cursor would move up
or down. Because this interfered with the browser's native scrolling
with up/down keys, that behavior has been removed. The j/k keys still
work as they did before.

Bug: Issue 7815
Change-Id: Iaf031f845293a3605a88a9e656eb000b0e4e196f
This commit is contained in:
Becky Siegel
2017-11-28 17:41:20 -08:00
parent e57f06e0d4
commit 7b550ef34b
2 changed files with 16 additions and 2 deletions

View File

@@ -493,11 +493,14 @@
return;
}
e.preventDefault();
if (this._showInlineDiffs) {
e.preventDefault();
this.$.diffCursor.moveDown();
this._displayLine = true;
} else {
// Down key
if (this.getKeyboardEvent(e).keyCode === 40) { return; }
e.preventDefault();
this.$.fileCursor.next();
this.selectedIndex = this.$.fileCursor.index;
}
@@ -508,11 +511,14 @@
return;
}
e.preventDefault();
if (this._showInlineDiffs) {
e.preventDefault();
this.$.diffCursor.moveUp();
this._displayLine = true;
} else {
// Up key
if (this.getKeyboardEvent(e).keyCode === 38) { return; }
e.preventDefault();
this.$.fileCursor.previous();
this.selectedIndex = this.$.fileCursor.index;
}

View File

@@ -520,6 +520,10 @@ limitations under the License.
// j with a modifier should not move the cursor.
MockInteractions.pressAndReleaseKeyOn(element, 74, 'shift', 'j');
assert.equal(element.$.fileCursor.index, 0);
// down should not move the cursor.
MockInteractions.pressAndReleaseKeyOn(element, 40, null, 'down');
assert.equal(element.$.fileCursor.index, 0);
MockInteractions.pressAndReleaseKeyOn(element, 74, null, 'j');
assert.equal(element.$.fileCursor.index, 1);
assert.equal(element.selectedIndex, 1);
@@ -533,6 +537,10 @@ limitations under the License.
MockInteractions.pressAndReleaseKeyOn(element, 75, 'shift', 'k');
assert.equal(element.$.fileCursor.index, 2);
// up should not move the cursor.
MockInteractions.pressAndReleaseKeyOn(element, 38, null, 'down');
assert.equal(element.$.fileCursor.index, 2);
MockInteractions.pressAndReleaseKeyOn(element, 75, null, 'k');
assert.equal(element.$.fileCursor.index, 1);
assert.equal(element.selectedIndex, 1);