Fix copy/paste edge case

In some cases, even though the copy selection was a valid one, the
target is something existing outside the content element. One specific
instance of this is when selecting lines by clicking/dragging along line
numbers.

Bug: Issue 5325
Change-Id: I3496a9d2432201aae6ef43a63ccca601a3bcd309
This commit is contained in:
Kasper Nilsson
2017-01-24 09:47:18 -08:00
parent 5dd17b647e
commit 13ab50938a
2 changed files with 11 additions and 9 deletions

View File

@@ -113,7 +113,7 @@
var commentSelected = false;
var target = this._getCopyEventTarget(e);
if (target.type === 'textarea') { return; }
if (!this._elementDescendedFromClass(target, 'content')) { return; }
if (!this._elementDescendedFromClass(target, 'diff-row')) { return; }
if (this.classList.contains(SelectionClass.COMMENT)) {
commentSelected = true;
}

View File

@@ -28,7 +28,7 @@ limitations under the License.
<template>
<gr-diff-selection>
<table id="diffTable" class="side-by-side">
<tr>
<tr class="diff-row">
<td class="lineNum left" data-value="1">1</td>
<td class="content">
<div class="contentText" data-side="left">ba ba</div>
@@ -45,7 +45,7 @@ limitations under the License.
<div class="contentText" data-side="right">some other text</div>
</td>
</tr>
<tr>
<tr class="diff-row">
<td class="lineNum left" data-value="2">2</td>
<td class="content">
<div class="contentText" data-side="left">zin</div>
@@ -62,7 +62,7 @@ limitations under the License.
</div>
</td>
</tr>
<tr>
<tr class="diff-row">
<td class="lineNum left" data-value="3">3</td>
<td class="content">
<div class="contentText" data-side="left">ga ga</div>
@@ -75,11 +75,8 @@ limitations under the License.
</div>
</td>
<td class="lineNum right" data-value="3">3</td>
<td class="other">
<div class="contentText" data-side="right">some other text</div>
</td>
</tr>
<tr>
<tr class="diff-row">
<td class="lineNum left" data-value="4">4</td>
<td class="content">
<div class="contentText" data-side="left">ga ga</div>
@@ -91,6 +88,11 @@ limitations under the License.
</td>
<td class="lineNum right" data-value="4">4</td>
</tr>
<tr class="not-diff-row">
<td class="other">
<div class="contentText" data-side="right">some other text</div>
</td>
</tr>
</table>
</gr-diff-selection>
</template>
@@ -168,7 +170,7 @@ limitations under the License.
test('ignores copy for non-content Element', function() {
sandbox.stub(element, '_getSelectedText');
emulateCopyOn(element.querySelector('.other'));
emulateCopyOn(element.querySelector('.not-diff-row'));
assert.isFalse(element._getSelectedText.called);
});