Merge "Fix getTargetDiffElement for polymer 2"

This commit is contained in:
Tao Zhou
2019-10-10 13:58:43 +00:00
committed by Gerrit Code Review
2 changed files with 16 additions and 3 deletions

View File

@@ -194,9 +194,13 @@
},
getTargetDiffElement() {
// Find the parent diff element of the cursor row.
for (let diff = this.diffRow; diff; diff = diff.parentElement) {
if (diff.tagName === 'GR-DIFF') { return diff; }
if (!this.diffRow) return null;
const hostOwner = Polymer.dom(/** @type {Node} */ (this.diffRow))
.getOwnerRoot();
if (hostOwner && hostOwner.host &&
hostOwner.host.tagName === 'GR-DIFF') {
return hostOwner.host;
}
return null;
},

View File

@@ -249,6 +249,15 @@ limitations under the License.
diffElement._diffChanged(mockDiffResponse.diffResponse);
});
test('getTargetDiffElement', () => {
cursorElement.initialLineNumber = 1;
assert.isTrue(!!cursorElement.diffRow);
assert.equal(
cursorElement.getTargetDiffElement(),
diffElement
);
});
test('getAddress', () => {
// It should initialize to the first chunk: line 5 of the revision.
assert.deepEqual(cursorElement.getAddress(),