Move the diff cursor when the diff content is tapped

When a user taps a line number in a diff, the cursor is moved to that
line and that side of the diff. However, if the user taps the text
content of a diff, the cursor was not moved. With this change, the
cursor is moved to the appropriate line and side of a diff when either
is tapped.

Bug: Issue 4215
Change-Id: I47d24f678f487eb3f8173ea5572865a589d845e4
This commit is contained in:
Wyatt Allen
2016-06-21 12:43:25 -07:00
parent 8fea317a86
commit 66bfe0005d
2 changed files with 46 additions and 0 deletions

View File

@@ -162,6 +162,9 @@
this.$.diffBuilder.showContext(e.detail.groups, e.detail.section);
} else if (el.classList.contains('lineNum')) {
this.addDraftAtLine(el);
} if (el.classList.contains('content')) {
var target = this.$.diffBuilder.getLineElByChild(el);
if (target) { this._selectLine(target); }
}
},

View File

@@ -254,6 +254,49 @@ limitations under the License.
element.reload();
});
});
test('_handleTap lineNum', function(done) {
var addDraftStub = sinon.stub(element, 'addDraftAtLine');
var el = document.createElement('div');
el.className = 'lineNum';
el.addEventListener('click', function(e) {
element._handleTap(e);
assert.isTrue(addDraftStub.called);
assert.equal(addDraftStub.lastCall.args[0], el);
done();
});
el.click();
});
test('_handleTap context', function(done) {
var showContextStub = sinon.stub(element.$.diffBuilder, 'showContext');
var el = document.createElement('div');
el.className = 'showContext';
el.addEventListener('click', function(e) {
element._handleTap(e);
assert.isTrue(showContextStub.called);
done();
});
el.click();
});
test('_handleTap content', function(done) {
var content = document.createElement('div');
var lineEl = document.createElement('div');
var selectStub = sinon.stub(element, '_selectLine');
var getLineStub = sinon.stub(element.$.diffBuilder, 'getLineElByChild',
function() { return lineEl; });
content.className = 'content';
content.addEventListener('click', function(e) {
element._handleTap(e);
assert.isTrue(selectStub.called);
assert.equal(selectStub.lastCall.args[0], lineEl);
done();
});
content.click();
});
});
suite('logged in', function() {