Skip to content

Commit 6dea2ba

Browse files
author
epriestley
committedApr 9, 2018
Fix DocumentEngine line behaviors in Diffusion
Summary: Ref T13105. Fixes some issues with line linking and highlighting under DocumentEngine: - Adding `$1-3` to the URI didn't work correctly with query parameters. - Reading `$1-3` from the URI didn't work correctly because Diffusion parses them slightly abnormally. Test Plan: Clicked/dragged lines to select them. Observed URI. Reloaded page, got the right selection. Reviewers: mydeveloperday Reviewed By: mydeveloperday Maniphest Tasks: T13105 Differential Revision: https://secure.phabricator.com/D19305
1 parent 1fde4a9 commit 6dea2ba

File tree

5 files changed

+49
-27
lines changed

5 files changed

+49
-27
lines changed
 

‎resources/celerity/map.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@
473473
'rsrc/js/core/behavior-keyboard-pager.js' => 'a8da01f0',
474474
'rsrc/js/core/behavior-keyboard-shortcuts.js' => '01fca1f0',
475475
'rsrc/js/core/behavior-lightbox-attachments.js' => '6b31879a',
476-
'rsrc/js/core/behavior-line-linker.js' => '13e39479',
476+
'rsrc/js/core/behavior-line-linker.js' => 'febf4ae7',
477477
'rsrc/js/core/behavior-more.js' => 'a80d0378',
478478
'rsrc/js/core/behavior-object-selector.js' => '77c1f0b0',
479479
'rsrc/js/core/behavior-oncopy.js' => '2926fff2',
@@ -638,7 +638,7 @@
638638
'javelin-behavior-phabricator-gesture-example' => '558829c2',
639639
'javelin-behavior-phabricator-keyboard-pager' => 'a8da01f0',
640640
'javelin-behavior-phabricator-keyboard-shortcuts' => '01fca1f0',
641-
'javelin-behavior-phabricator-line-linker' => '13e39479',
641+
'javelin-behavior-phabricator-line-linker' => 'febf4ae7',
642642
'javelin-behavior-phabricator-nav' => '836f966d',
643643
'javelin-behavior-phabricator-notification-example' => '8ce821c5',
644644
'javelin-behavior-phabricator-object-selector' => '77c1f0b0',
@@ -964,12 +964,6 @@
964964
'javelin-install',
965965
'javelin-util',
966966
),
967-
'13e39479' => array(
968-
'javelin-behavior',
969-
'javelin-stratcom',
970-
'javelin-dom',
971-
'javelin-history',
972-
),
973967
'15d5ff71' => array(
974968
'aphront-typeahead-control-css',
975969
'phui-tag-view-css',
@@ -2174,6 +2168,12 @@
21742168
'javelin-view-visitor',
21752169
'javelin-util',
21762170
),
2171+
'febf4ae7' => array(
2172+
'javelin-behavior',
2173+
'javelin-stratcom',
2174+
'javelin-dom',
2175+
'javelin-history',
2176+
),
21772177
),
21782178
'packages' => array(
21792179
'conpherence.pkg.css' => array(

‎src/aphront/AphrontRequest.php

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public function getURIData($key, $default = null) {
6161
*/
6262
public function getURILineRange($key, $limit) {
6363
$range = $this->getURIData($key);
64+
return self::parseURILineRange($range, $limit);
65+
}
66+
67+
public static function parseURILineRange($range, $limit) {
6468
if (!strlen($range)) {
6569
return null;
6670
}

‎src/applications/diffusion/document/DiffusionDocumentRenderingEngine.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ public function getDiffusionRequest() {
1414
return $this->diffusionRequest;
1515
}
1616

17-
protected function getSelectedDocumentEngineKey() {
18-
return $this->getRequest()->getStr('as');
19-
}
20-
2117
protected function newRefViewURI(
2218
PhabricatorDocumentRef $ref,
2319
PhabricatorDocumentEngine $engine) {
@@ -58,6 +54,15 @@ protected function newRefRenderURI(
5854
));
5955
}
6056

57+
protected function getSelectedDocumentEngineKey() {
58+
return $this->getRequest()->getStr('as');
59+
}
60+
61+
protected function getSelectedLineRange() {
62+
$range = $this->getDiffusionRequest()->getLine();
63+
return AphrontRequest::parseURILineRange($range, 1000);
64+
}
65+
6166
protected function addApplicationCrumbs(
6267
PHUICrumbsView $crumbs,
6368
PhabricatorDocumentRef $ref = null) {

‎src/applications/files/document/render/PhabricatorDocumentRenderingEngine.php

+17-13
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ final public function newDocumentView(PhabricatorDocumentRef $ref) {
5454
}
5555
$engine = $engines[$engine_key];
5656

57-
$lines = $request->getURILineRange('lines', 1000);
57+
$lines = $this->getSelectedLineRange();
5858
if ($lines) {
5959
$engine->setHighlightedLines(range($lines[0], $lines[1]));
6060
}
@@ -157,18 +157,6 @@ final public function newDocumentView(PhabricatorDocumentRef $ref) {
157157
->appendChild($viewport);
158158
}
159159

160-
abstract protected function newRefViewURI(
161-
PhabricatorDocumentRef $ref,
162-
PhabricatorDocumentEngine $engine);
163-
164-
abstract protected function newRefRenderURI(
165-
PhabricatorDocumentRef $ref,
166-
PhabricatorDocumentEngine $engine);
167-
168-
protected function getSelectedDocumentEngineKey() {
169-
return $this->getRequest()->getURIData('engineKey');
170-
}
171-
172160
final public function newRenderResponse(PhabricatorDocumentRef $ref) {
173161
$request = $this->getRequest();
174162
$viewer = $request->getViewer();
@@ -280,6 +268,22 @@ protected function newCrumbs() {
280268
return $crumbs;
281269
}
282270

271+
abstract protected function newRefViewURI(
272+
PhabricatorDocumentRef $ref,
273+
PhabricatorDocumentEngine $engine);
274+
275+
abstract protected function newRefRenderURI(
276+
PhabricatorDocumentRef $ref,
277+
PhabricatorDocumentEngine $engine);
278+
279+
protected function getSelectedDocumentEngineKey() {
280+
return $this->getRequest()->getURIData('engineKey');
281+
}
282+
283+
protected function getSelectedLineRange() {
284+
return $this->getRequest()->getURILineRange('lines', 1000);
285+
}
286+
283287
protected function addApplicationCrumbs(
284288
PHUICrumbsView $crumbs,
285289
PhabricatorDocumentRef $ref = null) {

‎webroot/rsrc/js/core/behavior-line-linker.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,26 @@ JX.behavior('phabricator-line-linker', function() {
144144
var o = getRowNumber(origin);
145145
var t = getRowNumber(target);
146146
var uri = JX.Stratcom.getData(root).uri;
147+
var path;
147148

148149
if (!uri) {
149-
uri = ('' + window.location).split('$')[0];
150+
uri = JX.$U(window.location);
151+
path = uri.getPath();
152+
path = path.replace(/\$[\d-]+$/, '');
153+
uri.setPath(path);
154+
uri = uri.toString();
150155
}
151156

152157
origin = null;
153158
target = null;
154159
root = null;
155160

156161
var lines = (o == t ? o : Math.min(o, t) + '-' + Math.max(o, t));
157-
uri = uri + '$' + lines;
162+
163+
uri = JX.$U(uri);
164+
path = uri.getPath();
165+
path = path + '$' + lines;
166+
uri = uri.setPath(path).toString();
158167

159168
JX.History.replace(uri);
160169

0 commit comments

Comments
 (0)
Failed to load comments.