Correct various minor diff copy behaviors

Summary:
Ref T12822. Fixes a few things:

  - Firefox selection of weird ranges with an inline between the start and end of the range now works correctly.
  - "Show More Context" rows now render, highlight, and select properly.
  - Prepares for nodes to have copy-text which is different from display-text.
  - Don't do anything too fancy in 1-up/unified mode. We don't copy line numbers after the `content: attr(data-n)` change, but that's as far as we go, because trying to do more than that is kind of weird and not terribly intuitive.

Test Plan:
  - Selected and copied weird ranges in Firefox.
  - Kept an eye on "Show More Context" rows across select and copy operations.
  - Generally poked around in Safari/Firefox/Chrome.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T12822

Differential Revision: https://secure.phabricator.com/D20192
This commit is contained in:
epriestley
2019-02-17 07:58:26 -08:00
parent 37f12a05ea
commit efccd75ae3
6 changed files with 175 additions and 77 deletions

View File

@@ -1246,8 +1246,24 @@ JX.install('DiffChangesetList', {
return changeset.getInlineForRow(inline_row);
},
getLineNumberFromHeader: function(th) {
return parseInt(th.getAttribute('data-n'));
getLineNumberFromHeader: function(node) {
var n = parseInt(node.getAttribute('data-n'));
if (!n) {
return null;
}
// If this is a line number that's part of a row showing more context,
// we don't want to let users leave inlines here.
try {
JX.DOM.findAbove(node, 'tr', 'context-target');
return null;
} catch (ex) {
// Ignore.
}
return n;
},
getDisplaySideFromHeader: function(th) {
@@ -1295,7 +1311,7 @@ JX.install('DiffChangesetList', {
},
_updateRange: function(target, is_out) {
// Don't update the range if this "<th />" doesn't correspond to a line
// Don't update the range if this target doesn't correspond to a line
// number. For instance, this may be a dead line number, like the empty
// line numbers on the left hand side of a newly added file.
var number = this.getLineNumberFromHeader(target);