Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/diff/PhabricatorDocumentEngineBlocks.php
| <?php | <?php | ||||
| final class PhabricatorDocumentEngineBlocks | final class PhabricatorDocumentEngineBlocks | ||||
| extends Phobject { | extends Phobject { | ||||
| private $lists = array(); | private $lists = array(); | ||||
| private $messages = array(); | private $messages = array(); | ||||
| private $rangeMin; | |||||
| private $rangeMax; | |||||
| private $revealedIndexes; | |||||
| private $layoutAvailableRowCount; | |||||
| public function setRange($min, $max) { | |||||
| $this->rangeMin = $min; | |||||
| $this->rangeMax = $max; | |||||
| return $this; | |||||
| } | |||||
| public function setRevealedIndexes(array $indexes) { | |||||
| $this->revealedIndexes = $indexes; | |||||
| return $this; | |||||
| } | |||||
| public function getLayoutAvailableRowCount() { | |||||
| if ($this->layoutAvailableRowCount === null) { | |||||
| throw new PhutilInvalidStateException('new...Layout'); | |||||
| } | |||||
| return $this->layoutAvailableRowCount; | |||||
| } | |||||
| public function addMessage($message) { | public function addMessage($message) { | ||||
| $this->messages[] = $message; | $this->messages[] = $message; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getMessages() { | public function getMessages() { | ||||
| return $this->messages; | return $this->messages; | ||||
| ▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | for ($ii = 0; $ii < $count; $ii++) { | ||||
| } | } | ||||
| $rows[] = array( | $rows[] = array( | ||||
| $old_block, | $old_block, | ||||
| $new_block, | $new_block, | ||||
| ); | ); | ||||
| } | } | ||||
| $this->layoutAvailableRowCount = count($rows); | |||||
| $rows = $this->revealIndexes($rows, true); | |||||
| $rows = $this->sliceRows($rows); | |||||
| return $rows; | return $rows; | ||||
| } | } | ||||
| public function newOneUpLayout() { | public function newOneUpLayout() { | ||||
| $rows = array(); | $rows = array(); | ||||
| $lists = $this->lists; | $lists = $this->lists; | ||||
| $idx = 0; | $idx = 0; | ||||
| Show All 16 Lines | while (true) { | ||||
| if (!$found_any) { | if (!$found_any) { | ||||
| break; | break; | ||||
| } | } | ||||
| $idx++; | $idx++; | ||||
| } | } | ||||
| $this->layoutAvailableRowCount = count($rows); | |||||
| $rows = $this->revealIndexes($rows, false); | |||||
| $rows = $this->sliceRows($rows); | |||||
| return $rows; | return $rows; | ||||
| } | } | ||||
| private function newDiffSpec(array $blocks) { | private function newDiffSpec(array $blocks) { | ||||
| $map = array(); | $map = array(); | ||||
| $list = array(); | $list = array(); | ||||
| Show All 9 Lines | private function newDiffSpec(array $blocks) { | ||||
| } | } | ||||
| return array( | return array( | ||||
| 'map' => $map, | 'map' => $map, | ||||
| 'list' => implode("\n", $list)."\n", | 'list' => implode("\n", $list)."\n", | ||||
| ); | ); | ||||
| } | } | ||||
| private function sliceRows(array $rows) { | |||||
| $min = $this->rangeMin; | |||||
| $max = $this->rangeMax; | |||||
| if ($min === null && $max === null) { | |||||
| return $rows; | |||||
| } | |||||
| if ($max === null) { | |||||
| return array_slice($rows, $min, null, true); | |||||
| } | |||||
| if ($min === null) { | |||||
| $min = 0; | |||||
| } | |||||
| return array_slice($rows, $min, $max - $min, true); | |||||
| } | |||||
| private function revealIndexes(array $rows, $is_vector) { | |||||
| if ($this->revealedIndexes === null) { | |||||
| return $rows; | |||||
| } | |||||
| foreach ($this->revealedIndexes as $index) { | |||||
| if (!isset($rows[$index])) { | |||||
| continue; | |||||
| } | |||||
| if ($is_vector) { | |||||
| foreach ($rows[$index] as $block) { | |||||
| if ($block !== null) { | |||||
| $block->setIsVisible(true); | |||||
| } | |||||
| } | |||||
| } else { | |||||
| $rows[$index]->setIsVisible(true); | |||||
| } | |||||
| } | |||||
| return $rows; | |||||
| } | |||||
| } | } | ||||