Merge "Set display line on inline diffs"

This commit is contained in:
Wyatt Allen
2017-06-01 16:41:32 +00:00
committed by Gerrit Code Review
3 changed files with 31 additions and 0 deletions

View File

@@ -323,6 +323,7 @@ limitations under the License.
if="[[_isFileExpanded(file.__path, _expandedFilePaths.*)]]">
<gr-diff
no-auto-render
display-line="[[_displayLine]]"
inline-index=[[index]]
hidden="[[!_isFileExpanded(file.__path, _expandedFilePaths.*)]]"
change-num="[[changeNum]]"

View File

@@ -110,6 +110,7 @@
type: Array,
value() { return []; },
},
_displayLine: Boolean,
},
behaviors: [
@@ -138,6 +139,7 @@
'n': '_handleNKey',
'p': '_handlePKey',
'shift+a': '_handleCapitalAKey',
'esc': '_handleEscKey',
},
reload() {
@@ -482,6 +484,7 @@
e.preventDefault();
if (this._showInlineDiffs) {
this.$.diffCursor.moveDown();
this._displayLine = true;
} else {
this.$.fileCursor.next();
this.selectedIndex = this.$.fileCursor.index;
@@ -496,6 +499,7 @@
e.preventDefault();
if (this._showInlineDiffs) {
this.$.diffCursor.moveUp();
this._displayLine = true;
} else {
this.$.fileCursor.previous();
this.selectedIndex = this.$.fileCursor.index;
@@ -895,5 +899,12 @@
}
}
},
_handleEscKey(e) {
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
this._displayLine = false;
},
});
})();

View File

@@ -1222,5 +1222,24 @@ limitations under the License.
element._openSelectedFile();
assert.isTrue(showStub.called);
});
test('_displayLine', () => {
sandbox.stub(element, 'shouldSuppressKeyboardShortcut', () => false);
sandbox.stub(element, 'modifierPressed', () => false);
element._showInlineDiffs = true;
const mockEvent = {preventDefault() {}};
element._displayLine = false;
element._handleDownKey(mockEvent);
assert.isTrue(element._displayLine);
element._displayLine = false;
element._handleUpKey(mockEvent);
assert.isTrue(element._displayLine);
element._displayLine = true;
element._handleEscKey(mockEvent);
assert.isFalse(element._displayLine);
});
});
</script>