1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

Improve select-to-comment behavior in Firefox and on unified diffs

Summary:
Ref T13513.

  - Firefox represents multiple selected rows as a discontinuous range. Accommodate this.
  - Unified diffs don't have a "copy" marker. Do something sort-of-reasonable for them.

Test Plan:
  - Selected multiple lines of content in Firefox, got an option to add a comment.
  - Selected content in unified mode, got an option to add a comment.

Maniphest Tasks: T13513

Differential Revision: https://secure.phabricator.com/D21249
This commit is contained in:
epriestley 2020-05-13 13:37:42 -07:00
parent 42378ea393
commit ebef22ccc1
2 changed files with 59 additions and 35 deletions

View file

@ -13,7 +13,7 @@ return array(
'core.pkg.js' => '0efaf0ac',
'dark-console.pkg.js' => '187792c2',
'differential.pkg.css' => 'd71d4531',
'differential.pkg.js' => '06a7949c',
'differential.pkg.js' => 'ac6914bb',
'diffusion.pkg.css' => '42c75c37',
'diffusion.pkg.js' => 'a98c0bf7',
'maniphest.pkg.css' => '35995d6d',
@ -380,7 +380,7 @@ return array(
'rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js' => '1e413dc9',
'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => '0116d3e8',
'rsrc/js/application/diff/DiffChangeset.js' => '20715b98',
'rsrc/js/application/diff/DiffChangesetList.js' => '4a3639a1',
'rsrc/js/application/diff/DiffChangesetList.js' => '9d5b137e',
'rsrc/js/application/diff/DiffInline.js' => '6227a0e3',
'rsrc/js/application/diff/DiffPathView.js' => '8207abf9',
'rsrc/js/application/diff/DiffTreeView.js' => '5d83623b',
@ -775,7 +775,7 @@ return array(
'phabricator-darkmessage' => '26cd4b73',
'phabricator-dashboard-css' => '5a205b9d',
'phabricator-diff-changeset' => '20715b98',
'phabricator-diff-changeset-list' => '4a3639a1',
'phabricator-diff-changeset-list' => '9d5b137e',
'phabricator-diff-inline' => '6227a0e3',
'phabricator-diff-path-view' => '8207abf9',
'phabricator-diff-tree-view' => '5d83623b',
@ -1327,11 +1327,6 @@ return array(
'490e2e2e' => array(
'phui-oi-list-view-css',
),
'4a3639a1' => array(
'javelin-install',
'phuix-button-view',
'phabricator-diff-tree-view',
),
'4a7fb02b' => array(
'javelin-behavior',
'javelin-dom',
@ -1821,6 +1816,11 @@ return array(
'javelin-uri',
'phabricator-textareautils',
),
'9d5b137e' => array(
'javelin-install',
'phuix-button-view',
'phabricator-diff-tree-view',
),
'9f081f05' => array(
'javelin-behavior',
'javelin-dom',

View file

@ -2232,34 +2232,36 @@ JX.install('DiffChangesetList', {
_updateSourceSelection: function() {
var ranges = this._getSelectedRanges();
// If we have zero or more than one range, don't do anything.
if (ranges.length === 1) {
for (var ii = 0; ii < ranges.length; ii++) {
var range = ranges[ii];
var head = range.startContainer;
var last = range.endContainer;
var head_loc = this._getFragmentLocation(head);
var last_loc = this._getFragmentLocation(last);
if (head_loc === null || last_loc === null) {
break;
}
if (head_loc.changesetID !== last_loc.changesetID) {
break;
}
head_loc.offset += range.startOffset;
last_loc.offset += range.endOffset;
this._setSourceSelection(head_loc, last_loc);
return;
}
// In Firefox, selecting multiple rows gives us multiple ranges. In
// Safari and Chrome, we get a single range.
if (!ranges.length) {
this._setSourceSelection(null, null);
return;
}
this._setSourceSelection(null, null);
var min = 0;
var max = ranges.length - 1;
var head = ranges[min].startContainer;
var last = ranges[max].endContainer;
var head_loc = this._getFragmentLocation(head);
var last_loc = this._getFragmentLocation(last);
if (head_loc === null || last_loc === null) {
this._setSourceSelection(null, null);
return;
}
if (head_loc.changesetID !== last_loc.changesetID) {
this._setSourceSelection(null, null);
return;
}
head_loc.offset += ranges[min].startOffset;
last_loc.offset += ranges[max].endOffset;
this._setSourceSelection(head_loc, last_loc);
},
_setSourceSelection: function(start, end) {
@ -2382,6 +2384,8 @@ JX.install('DiffChangesetList', {
// Find the line number and display column for the fragment.
var line = null;
var column_count = -1;
var has_new = false;
var has_old = false;
var offset = null;
var target_node = null;
var td;
@ -2415,6 +2419,18 @@ JX.install('DiffChangesetList', {
while (cursor) {
if (cursor.getAttribute('data-copy-mode')) {
column_count++;
} else {
// In unified mode, the content column isn't currently marked
// with an attribute, and we can't count content columns anyway.
// Keep track of whether or not we see a "NL" (New Line) column
// and/or an "OL" (Old Line) column to try to puzzle out which
// side of the display change we're on.
if (cursor.id.match(/NL/)) {
has_new = true;
} else if (cursor.id.match(/OL/)) {
has_old = true;
}
}
var n = parseInt(cursor.getAttribute('data-n'));
@ -2434,7 +2450,15 @@ JX.install('DiffChangesetList', {
}
if (column_count < 0) {
return null;
if (has_new || has_old) {
if (has_new) {
column_count = 1;
} else {
column_count = 0;
}
} else {
return null;
}
}
var seen = 0;