@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.

Render proper "Show Context" links in DocumentEngine diffs, not just bullets

Summary:
Ref T13513. Currently, viewing a Jupyter document, hidden context just gets a plain "* * *" facade with no way to expand it.

Support click-to-expand, like source changes.

Test Plan:
- Clicked to expand various Jupyter diffs.
- Clicked to expand normal source changes.

Maniphest Tasks: T13513

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

+203 -31
+16
src/applications/differential/parser/DifferentialChangesetParser.php
··· 1084 1084 $vs = $id; 1085 1085 } 1086 1086 1087 + if ($mask_force) { 1088 + $engine_blocks->setRevealedIndexes(array_keys($mask_force)); 1089 + } 1090 + 1091 + if ($range_start !== null || $range_len !== null) { 1092 + $range_min = $range_start; 1093 + 1094 + if ($range_len === null) { 1095 + $range_max = null; 1096 + } else { 1097 + $range_max = (int)$range_start + (int)$range_len; 1098 + } 1099 + 1100 + $engine_blocks->setRange($range_min, $range_max); 1101 + } 1102 + 1087 1103 $renderer 1088 1104 ->setDocumentEngine($engine) 1089 1105 ->setDocumentEngineBlocks($engine_blocks);
+35 -6
src/applications/differential/render/DifferentialChangesetHTMLRenderer.php
··· 496 496 * @param int Total number of lines in the changeset. 497 497 * @return markup Rendered links. 498 498 */ 499 - protected function renderShowContextLinks($top, $len, $changeset_length) { 499 + protected function renderShowContextLinks( 500 + $top, 501 + $len, 502 + $changeset_length, 503 + $is_blocks = false) { 504 + 500 505 $block_size = 20; 501 506 $end = ($top + $len) - $block_size; 502 507 ··· 509 514 510 515 $links = array(); 511 516 517 + $block_display = new PhutilNumber($block_size); 518 + 512 519 if ($is_large_block) { 513 520 $is_first_block = ($top == 0); 514 521 if ($is_first_block) { 515 - $text = pht('Show First %d Line(s)', $block_size); 522 + if ($is_blocks) { 523 + $text = pht('Show First %s Block(s)', $block_display); 524 + } else { 525 + $text = pht('Show First %s Line(s)', $block_display); 526 + } 516 527 } else { 517 - $text = pht("\xE2\x96\xB2 Show %d Line(s)", $block_size); 528 + if ($is_blocks) { 529 + $text = pht("\xE2\x96\xB2 Show %s Block(s)", $block_display); 530 + } else { 531 + $text = pht("\xE2\x96\xB2 Show %s Line(s)", $block_display); 532 + } 518 533 } 519 534 520 535 $links[] = $this->renderShowContextLink( ··· 523 538 $text); 524 539 } 525 540 541 + if ($is_blocks) { 542 + $text = pht('Show All %s Block(s)', new PhutilNumber($len)); 543 + } else { 544 + $text = pht('Show All %s Line(s)', new PhutilNumber($len)); 545 + } 546 + 526 547 $links[] = $this->renderShowContextLink( 527 548 true, 528 549 "{$top}-{$len}/{$top}-{$len}", 529 - pht('Show All %d Line(s)', $len)); 550 + $text); 530 551 531 552 if ($is_large_block) { 532 553 $is_last_block = (($top + $len) >= $changeset_length); 533 554 if ($is_last_block) { 534 - $text = pht('Show Last %d Line(s)', $block_size); 555 + if ($is_blocks) { 556 + $text = pht('Show Last %s Block(s)', $block_display); 557 + } else { 558 + $text = pht('Show Last %s Line(s)', $block_display); 559 + } 535 560 } else { 536 - $text = "\xE2\x96\xBC ".pht('Show %d Line(s)', $block_size); 561 + if ($is_blocks) { 562 + $text = pht("\xE2\x96\xBC Show %s Block(s)", $block_display); 563 + } else { 564 + $text = pht("\xE2\x96\xBC Show %s Line(s)", $block_display); 565 + } 537 566 } 538 567 539 568 $links[] = $this->renderShowContextLink(
+41 -15
src/applications/differential/render/DifferentialChangesetTwoUpRenderer.php
··· 381 381 $old_comments = $this->getOldComments(); 382 382 $new_comments = $this->getNewComments(); 383 383 384 - $gap_view = javelin_tag( 385 - 'tr', 386 - array( 387 - 'sigil' => 'context-target', 388 - ), 389 - phutil_tag( 390 - 'td', 391 - array( 392 - 'colspan' => 6, 393 - 'class' => 'show-more', 394 - ), 395 - pht("\xE2\x80\xA2 \xE2\x80\xA2 \xE2\x80\xA2"))); 396 - 397 384 $rows = array(); 385 + $gap = array(); 398 386 $in_gap = false; 399 - foreach ($block_list->newTwoUpLayout() as $row) { 387 + 388 + // NOTE: The generated layout is affected by range constraints, and may 389 + // represent only a slice of the document. 390 + 391 + $layout = $block_list->newTwoUpLayout(); 392 + $available_count = $block_list->getLayoutAvailableRowCount(); 393 + 394 + foreach ($layout as $idx => $row) { 400 395 list($old, $new) = $row; 401 396 402 397 if ($old) { ··· 416 411 if (!$is_visible) { 417 412 if (!$in_gap) { 418 413 $in_gap = true; 419 - $rows[] = $gap_view; 420 414 } 415 + $gap[$idx] = $row; 421 416 continue; 422 417 } 423 418 424 419 if ($in_gap) { 425 420 $in_gap = false; 421 + $rows[] = $this->renderDocumentEngineGap( 422 + $gap, 423 + $available_count); 424 + $gap = array(); 426 425 } 427 426 428 427 if ($old) { ··· 577 576 ); 578 577 } 579 578 579 + if ($in_gap) { 580 + $rows[] = $this->renderDocumentEngineGap( 581 + $gap, 582 + $available_count); 583 + } 584 + 580 585 $output = $this->wrapChangeInTable($rows); 581 586 582 587 return $this->renderChangesetTable($output); ··· 614 619 return array( 615 620 'intercept-copy', 616 621 ); 622 + } 623 + 624 + private function renderDocumentEngineGap(array $gap, $available_count) { 625 + $content = $this->renderShowContextLinks( 626 + head_key($gap), 627 + count($gap), 628 + $available_count, 629 + $is_blocks = true); 630 + 631 + return javelin_tag( 632 + 'tr', 633 + array( 634 + 'sigil' => 'context-target', 635 + ), 636 + phutil_tag( 637 + 'td', 638 + array( 639 + 'colspan' => 6, 640 + 'class' => 'show-more', 641 + ), 642 + $content)); 617 643 } 618 644 619 645 }
+76
src/applications/files/diff/PhabricatorDocumentEngineBlocks.php
··· 5 5 6 6 private $lists = array(); 7 7 private $messages = array(); 8 + private $rangeMin; 9 + private $rangeMax; 10 + private $revealedIndexes; 11 + private $layoutAvailableRowCount; 12 + 13 + public function setRange($min, $max) { 14 + $this->rangeMin = $min; 15 + $this->rangeMax = $max; 16 + return $this; 17 + } 18 + 19 + public function setRevealedIndexes(array $indexes) { 20 + $this->revealedIndexes = $indexes; 21 + return $this; 22 + } 23 + 24 + public function getLayoutAvailableRowCount() { 25 + if ($this->layoutAvailableRowCount === null) { 26 + throw new PhutilInvalidStateException('new...Layout'); 27 + } 28 + 29 + return $this->layoutAvailableRowCount; 30 + } 8 31 9 32 public function addMessage($message) { 10 33 $this->messages[] = $message; ··· 115 138 ); 116 139 } 117 140 141 + $this->layoutAvailableRowCount = count($rows); 142 + 143 + $rows = $this->revealIndexes($rows, true); 144 + $rows = $this->sliceRows($rows); 145 + 118 146 return $rows; 119 147 } 120 148 ··· 147 175 $idx++; 148 176 } 149 177 178 + $this->layoutAvailableRowCount = count($rows); 179 + 180 + $rows = $this->revealIndexes($rows, false); 181 + $rows = $this->sliceRows($rows); 182 + 150 183 return $rows; 151 184 } 152 185 ··· 170 203 'map' => $map, 171 204 'list' => implode("\n", $list)."\n", 172 205 ); 206 + } 207 + 208 + private function sliceRows(array $rows) { 209 + $min = $this->rangeMin; 210 + $max = $this->rangeMax; 211 + 212 + if ($min === null && $max === null) { 213 + return $rows; 214 + } 215 + 216 + if ($max === null) { 217 + return array_slice($rows, $min, null, true); 218 + } 219 + 220 + if ($min === null) { 221 + $min = 0; 222 + } 223 + 224 + return array_slice($rows, $min, $max - $min, true); 225 + } 226 + 227 + private function revealIndexes(array $rows, $is_vector) { 228 + if ($this->revealedIndexes === null) { 229 + return $rows; 230 + } 231 + 232 + foreach ($this->revealedIndexes as $index) { 233 + if (!isset($rows[$index])) { 234 + continue; 235 + } 236 + 237 + if ($is_vector) { 238 + foreach ($rows[$index] as $block) { 239 + if ($block !== null) { 240 + $block->setIsVisible(true); 241 + } 242 + } 243 + } else { 244 + $rows[$index]->setIsVisible(true); 245 + } 246 + } 247 + 248 + return $rows; 173 249 } 174 250 175 251 }
+35 -10
src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php
··· 1069 1069 ), 1070 1070 ), 1071 1071 1072 - 'Show First %d Line(s)' => array( 1072 + 'Show First %s Line(s)' => array( 1073 1073 'Show First Line', 1074 - 'Show First %d Lines', 1074 + 'Show First %s Lines', 1075 1075 ), 1076 1076 1077 - "\xE2\x96\xB2 Show %d Line(s)" => array( 1077 + 'Show First %s Block(s)' => array( 1078 + 'Show First Block', 1079 + 'Show First %s Blocks', 1080 + ), 1081 + 1082 + "\xE2\x96\xB2 Show %s Line(s)" => array( 1078 1083 "\xE2\x96\xB2 Show Line", 1079 - "\xE2\x96\xB2 Show %d Lines", 1084 + "\xE2\x96\xB2 Show %s Lines", 1085 + ), 1086 + 1087 + "\xE2\x96\xB2 Show %s Block(s)" => array( 1088 + "\xE2\x96\xB2 Show Block", 1089 + "\xE2\x96\xB2 Show %s Blocks", 1080 1090 ), 1081 1091 1082 - 'Show All %d Line(s)' => array( 1092 + 'Show All %s Line(s)' => array( 1083 1093 'Show Line', 1084 - 'Show All %d Lines', 1094 + 'Show All %s Lines', 1095 + ), 1096 + 1097 + 'Show All %s Block(s)' => array( 1098 + 'Show Block', 1099 + 'Show All %s Blocks', 1085 1100 ), 1086 1101 1087 - "\xE2\x96\xBC Show %d Line(s)" => array( 1102 + "\xE2\x96\xBC Show %s Line(s)" => array( 1088 1103 "\xE2\x96\xBC Show Line", 1089 - "\xE2\x96\xBC Show %d Lines", 1104 + "\xE2\x96\xBC Show %s Lines", 1090 1105 ), 1091 1106 1092 - 'Show Last %d Line(s)' => array( 1107 + "\xE2\x96\xBC Show %s Block(s)" => array( 1108 + "\xE2\x96\xBC Show Block", 1109 + "\xE2\x96\xBC Show %s Blocks", 1110 + ), 1111 + 1112 + 'Show Last %s Line(s)' => array( 1093 1113 'Show Last Line', 1094 - 'Show Last %d Lines', 1114 + 'Show Last %s Lines', 1115 + ), 1116 + 1117 + 'Show Last %s Block(s)' => array( 1118 + 'Show Last Block', 1119 + 'Show Last %s Blocks', 1095 1120 ), 1096 1121 1097 1122 '%s marked %s inline comment(s) as done and %s inline comment(s) as '.