Skip to content

Commit 3ee6b53

Browse files
author
epriestley
committedMay 14, 2020
Improve offset/range inline behavior for rich diffs and unified diffs
Summary: Ref T13513. The way I'm highlighting lines won't work for Jupyter notebooks or other complex content blocks, and I don't see an obvious way to make it work that's reasonably robust. However, we can just ignore the range behavior for complex content and treat the entire block as selected. This isn't quite as fancy as the source behavior, but pretty good. Also, adjust unified diff behavior to work correctly with highlighting and range selection. Test Plan: - Used range selection in a Jupyter notebook, got reasonable behavior (range is treated as "entire block"). - Used range selection in a unified diff, got equivalent behavior to 2-up diffs. Maniphest Tasks: T13513 Differential Revision: https://secure.phabricator.com/D21257
1 parent fbd57ad commit 3ee6b53

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed
 

‎resources/celerity/map.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'core.pkg.js' => '845355f4',
1414
'dark-console.pkg.js' => '187792c2',
1515
'differential.pkg.css' => '319dca29',
16-
'differential.pkg.js' => 'ccf7bdca',
16+
'differential.pkg.js' => '695827fc',
1717
'diffusion.pkg.css' => '42c75c37',
1818
'diffusion.pkg.js' => 'a98c0bf7',
1919
'maniphest.pkg.css' => '35995d6d',
@@ -380,7 +380,7 @@
380380
'rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js' => '1e413dc9',
381381
'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => '0116d3e8',
382382
'rsrc/js/application/diff/DiffChangeset.js' => 'bfdae878',
383-
'rsrc/js/application/diff/DiffChangesetList.js' => 'a00bf62d',
383+
'rsrc/js/application/diff/DiffChangesetList.js' => 'b1b8500b',
384384
'rsrc/js/application/diff/DiffInline.js' => 'b00168c1',
385385
'rsrc/js/application/diff/DiffPathView.js' => '8207abf9',
386386
'rsrc/js/application/diff/DiffTreeView.js' => '5d83623b',
@@ -775,7 +775,7 @@
775775
'phabricator-darkmessage' => '26cd4b73',
776776
'phabricator-dashboard-css' => '5a205b9d',
777777
'phabricator-diff-changeset' => 'bfdae878',
778-
'phabricator-diff-changeset-list' => 'a00bf62d',
778+
'phabricator-diff-changeset-list' => 'b1b8500b',
779779
'phabricator-diff-inline' => 'b00168c1',
780780
'phabricator-diff-path-view' => '8207abf9',
781781
'phabricator-diff-tree-view' => '5d83623b',
@@ -1808,11 +1808,6 @@
18081808
'javelin-util',
18091809
'phabricator-keyboard-shortcut',
18101810
),
1811-
'a00bf62d' => array(
1812-
'javelin-install',
1813-
'phuix-button-view',
1814-
'phabricator-diff-tree-view',
1815-
),
18161811
'a17b84f1' => array(
18171812
'javelin-behavior',
18181813
'javelin-dom',
@@ -1932,6 +1927,11 @@
19321927
'javelin-stratcom',
19331928
'javelin-dom',
19341929
),
1930+
'b1b8500b' => array(
1931+
'javelin-install',
1932+
'phuix-button-view',
1933+
'phabricator-diff-tree-view',
1934+
),
19351935
'b26a41e4' => array(
19361936
'javelin-behavior',
19371937
'javelin-stratcom',

‎src/applications/differential/render/DifferentialChangesetOneUpRenderer.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ protected function renderPrimitives(array $primitives, $rows) {
4545
'span',
4646
array(
4747
'aural' => true,
48+
'data-aural' => true,
4849
),
4950
'- ');
5051

5152
$aural_plus = javelin_tag(
5253
'span',
5354
array(
5455
'aural' => true,
56+
'data-aural' => true,
5557
),
5658
'+ ');
5759

@@ -171,7 +173,15 @@ protected function renderPrimitives(array $primitives, $rows) {
171173
}
172174

173175
$cells[] = $no_copy;
174-
$cells[] = phutil_tag('td', array('class' => $class), $render);
176+
177+
$cells[] = phutil_tag(
178+
'td',
179+
array(
180+
'class' => $class,
181+
'data-copy-mode' => 'copy-unified',
182+
),
183+
$render);
184+
175185
$cells[] = $no_coverage;
176186
}
177187

‎webroot/rsrc/js/application/diff/DiffChangesetList.js

+36-6
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,22 @@ JX.install('DiffChangesetList', {
441441

442442
this._setSourceSelection(null, null);
443443

444-
var config = {
445-
startOffset: start.offset,
446-
endOffset: end.offset
447-
};
448-
449444
var changeset = start.changeset;
445+
446+
var config = {};
447+
if (changeset.getResponseDocumentEngineKey() === null) {
448+
// If the changeset is using a document renderer, we ignore the
449+
// selection range and just treat this as a comment from the first
450+
// block to the last block.
451+
452+
// If we don't discard the range, we later render a bogus highlight
453+
// if the block content is complex (like a Jupyter notebook cell
454+
// with images).
455+
456+
config.startOffset = start.offset;
457+
config.endOffset = end.offset;
458+
}
459+
450460
changeset.newInlineForRange(start.targetNode, end.targetNode, config);
451461
},
452462

@@ -2623,7 +2633,7 @@ JX.install('DiffChangesetList', {
26232633
td = cells[cells.length - 1];
26242634
is_end = true;
26252635
} else {
2626-
td = JX.DOM.findAbove(fragment, 'td');
2636+
td = this._findContentCell(fragment);
26272637
is_end = false;
26282638
}
26292639

@@ -2707,6 +2717,16 @@ JX.install('DiffChangesetList', {
27072717
},
27082718

27092719
_getSelectionOffset: function(node, target) {
2720+
// If this is an aural hint node in a unified diff, ignore it when
2721+
// calculating the selection offset.
2722+
if (node.getAttribute && node.getAttribute('data-aural')) {
2723+
return {
2724+
offset: 0,
2725+
content: '',
2726+
found: false
2727+
};
2728+
}
2729+
27102730
if (!node.childNodes || !node.childNodes.length) {
27112731
return {
27122732
offset: node.textContent.length,
@@ -2764,6 +2784,16 @@ JX.install('DiffChangesetList', {
27642784

27652785
_isContentCell: function(node) {
27662786
return !!node.getAttribute('data-copy-mode');
2787+
},
2788+
2789+
_findContentCell: function(node) {
2790+
var cursor = node;
2791+
while (true) {
2792+
cursor = JX.DOM.findAbove(cursor, 'td');
2793+
if (this._isContentCell(cursor)) {
2794+
return cursor;
2795+
}
2796+
}
27672797
}
27682798

27692799
}

0 commit comments

Comments
 (0)
Failed to load comments.