@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Multi-line highlighting in Diffusion.

Summary: Currently, Diffusion supports highlighting of line ranges passed in the URI. It would be helpful to be able to highlight multiple line ranges.

Test Plan: Accessed directly via URL in my sandbox. Seems to work. I'm not sure what other components use this functionality, but this change should be backwards compatible.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D2921

+37 -14
+23 -13
src/applications/diffusion/controller/DiffusionBrowseFileController.php
··· 293 293 $epoch_range = ($epoch_max - $epoch_min) + 1; 294 294 } 295 295 296 - $min_line = 0; 297 - $line = $drequest->getLine(); 298 - if (strpos($line, '-') !== false) { 299 - list($min, $max) = explode('-', $line, 2); 300 - $min_line = min($min, $max); 301 - $max_line = max($min, $max); 302 - } else if (strlen($line)) { 303 - $min_line = $line; 304 - $max_line = $line; 296 + $line_arr = array(); 297 + $line_str = $drequest->getLine(); 298 + $ranges = explode(',', $line_str); 299 + foreach ($ranges as $range) { 300 + if (strpos($range, '-') !== false) { 301 + list($min, $max) = explode('-', $range, 2); 302 + $line_arr[] = array( 303 + 'min' => min($min, $max), 304 + 'max' => max($min, $max), 305 + ); 306 + } else if (strlen($range)) { 307 + $line_arr[] = array( 308 + 'min' => $range, 309 + 'max' => $range, 310 + ); 311 + } 305 312 } 306 313 307 314 $display = array(); ··· 366 373 } 367 374 } 368 375 369 - if ($min_line) { 370 - if ($line_number == $min_line) { 376 + if ($line_arr) { 377 + if ($line_number == $line_arr[0]['min']) { 371 378 $display_line['target'] = true; 372 379 } 373 - if ($line_number >= $min_line && $line_number <= $max_line) { 374 - $display_line['highlighted'] = true; 380 + foreach ($line_arr as $range) { 381 + if ($line_number >= $range['min'] && 382 + $line_number <= $range['max']) { 383 + $display_line['highlighted'] = true; 384 + } 375 385 } 376 386 } 377 387
+1 -1
src/applications/diffusion/request/DiffusionRequest.php
··· 475 475 // Consume the back part of the URI, up to the first "$". Use a negative 476 476 // lookbehind to prevent matching '$$'. We double the '$' symbol when 477 477 // encoding so that files with names like "money/$100" will survive. 478 - $pattern = '@(?:(?:^|[^$])(?:[$][$])*)[$]([\d-]+)$@'; 478 + $pattern = '@(?:(?:^|[^$])(?:[$][$])*)[$]([\d-,]+)$@'; 479 479 if (preg_match($pattern, $blob, $matches)) { 480 480 $result['line'] = $matches[1]; 481 481 $blob = substr($blob, 0, -(strlen($matches[1]) + 1));
+13
src/applications/diffusion/request/__tests__/DiffusionURITestCase.php
··· 55 55 'commit' => '$;;semicolon;;$$', 56 56 'line' => '100', 57 57 ), 58 + 'branch/path.ext;abc$3-5,7-12,14' => array( 59 + 'branch' => 'branch', 60 + 'path' => 'path.ext', 61 + 'commit' => 'abc', 62 + 'line' => '3-5,7-12,14', 63 + ), 58 64 ); 59 65 60 66 foreach ($map as $input => $expect) { ··· 139 145 'action' => 'rendering-ref', 140 146 'path' => 'path/to/file.ext', 141 147 'commit' => 'abc', 148 + ), 149 + '/diffusion/A/browse/branch/path.ext$3-5%2C7-12%2C14' => array( 150 + 'action' => 'browse', 151 + 'callsign' => 'A', 152 + 'branch' => 'branch', 153 + 'path' => 'path.ext', 154 + 'line' => '3-5,7-12,14', 142 155 ), 143 156 ); 144 157