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

Restore editor behavior to Diffusion and support "\" shortcut

Summary:
Ref T13515. This restores the "Open in Editor" behavior to Diffusion, and makes "\" work there.

The URI pattern is now sent as a structured template to the client, so the code will work properly if a file path contains "%l".

Test Plan:
- Clicked "Open in Editor" and pressed "\" in Diffusion when viewing a file.
- Clicked a line, hit "\", got the file opened to that line.

Maniphest Tasks: T13515

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

+78 -25
+8 -8
resources/celerity/map.php
··· 483 483 'rsrc/js/core/behavior-keyboard-pager.js' => '1325b731', 484 484 'rsrc/js/core/behavior-keyboard-shortcuts.js' => '42c44e8b', 485 485 'rsrc/js/core/behavior-lightbox-attachments.js' => 'c7e748bf', 486 - 'rsrc/js/core/behavior-line-linker.js' => 'e15c8b1f', 486 + 'rsrc/js/core/behavior-line-linker.js' => '590e6527', 487 487 'rsrc/js/core/behavior-linked-container.js' => '74446546', 488 488 'rsrc/js/core/behavior-more.js' => '506aa3f4', 489 489 'rsrc/js/core/behavior-object-selector.js' => '98ef467f', ··· 644 644 'javelin-behavior-phabricator-gesture-example' => '242dedd0', 645 645 'javelin-behavior-phabricator-keyboard-pager' => '1325b731', 646 646 'javelin-behavior-phabricator-keyboard-shortcuts' => '42c44e8b', 647 - 'javelin-behavior-phabricator-line-linker' => 'e15c8b1f', 647 + 'javelin-behavior-phabricator-line-linker' => '590e6527', 648 648 'javelin-behavior-phabricator-nav' => 'f166c949', 649 649 'javelin-behavior-phabricator-notification-example' => '29819b75', 650 650 'javelin-behavior-phabricator-object-selector' => '98ef467f', ··· 1452 1452 'javelin-util', 1453 1453 'javelin-magical-init', 1454 1454 ), 1455 + '590e6527' => array( 1456 + 'javelin-behavior', 1457 + 'javelin-stratcom', 1458 + 'javelin-dom', 1459 + 'javelin-history', 1460 + ), 1455 1461 '5a4e4a3b' => array( 1456 1462 'javelin-dom', 1457 1463 'javelin-util', ··· 2095 2101 'javelin-stratcom', 2096 2102 'javelin-dom', 2097 2103 'phuix-dropdown-menu', 2098 - ), 2099 - 'e15c8b1f' => array( 2100 - 'javelin-behavior', 2101 - 'javelin-stratcom', 2102 - 'javelin-dom', 2103 - 'javelin-history', 2104 2104 ), 2105 2105 'e5bdb730' => array( 2106 2106 'javelin-behavior',
+14 -8
src/applications/diffusion/controller/DiffusionBrowseController.php
··· 472 472 $viewer = $this->getViewer(); 473 473 $base_uri = $this->getRequest()->getRequestURI(); 474 474 475 - $user = $this->getRequest()->getUser(); 476 475 $repository = $drequest->getRepository(); 477 476 $path = $drequest->getPath(); 478 477 $line = nonempty((int)$drequest->getLine(), 1); 479 478 $buttons = array(); 480 479 481 - // TODO: Restore these behaviors. 482 - $editor_link = null; 483 - $template = null; 480 + $editor_uri = null; 481 + $editor_template = null; 482 + 483 + $link_engine = PhabricatorEditorURIEngine::newForViewer($viewer); 484 + if ($link_engine) { 485 + $link_engine->setRepository($repository); 486 + 487 + $editor_uri = $link_engine->getURIForPath($path, $line); 488 + $editor_template = $link_engine->getURITokensForPath($path); 489 + } 484 490 485 491 $buttons[] = 486 492 id(new PHUIButtonView()) ··· 494 500 ))) 495 501 ->setIcon('fa-backward'); 496 502 497 - if ($editor_link) { 503 + if ($editor_uri) { 498 504 $buttons[] = 499 505 id(new PHUIButtonView()) 500 506 ->setTag('a') 501 507 ->setText(pht('Open File')) 502 - ->setHref($editor_link) 508 + ->setHref($editor_uri) 503 509 ->setIcon('fa-pencil') 504 510 ->setID('editor_link') 505 - ->setMetadata(array('link_template' => $template)) 506 - ->setDisabled(!$editor_link) 511 + ->setMetadata(array('template' => $editor_template)) 512 + ->setDisabled(!$editor_uri) 507 513 ->setColor(PHUIButtonView::GREY); 508 514 } 509 515
+18 -6
src/infrastructure/editor/PhabricatorEditorURIEngine.php
··· 68 68 } 69 69 70 70 public function getURIForPath($path, $line) { 71 - $tokens = $this->getURITokensForRepository(); 71 + $tokens = $this->getURITokensForRepository($path); 72 72 73 73 $variables = array( 74 74 'f' => $this->escapeToken($path), ··· 80 80 return $this->newStringFromTokens($tokens); 81 81 } 82 82 83 - public function getURITokensForRepository() { 84 - if (!$this->repositoryTokens) { 85 - $this->repositoryTokens = $this->newURITokensForRepository(); 86 - } 83 + public function getURITokensForPath($path) { 84 + $tokens = $this->getURITokensForRepository($path); 87 85 88 - return $this->repositoryTokens; 86 + $variables = array( 87 + 'f' => $this->escapeToken($path), 88 + ); 89 + 90 + return $this->newTokensWithVariables($tokens, $variables); 89 91 } 90 92 91 93 public static function getVariableDefinitions() { ··· 119 121 'example' => '%', 120 122 ), 121 123 ); 124 + } 125 + 126 + private function getURITokensForRepository() { 127 + if (!$this->repositoryTokens) { 128 + $this->repositoryTokens = $this->newURITokensForRepository(); 129 + } 130 + 131 + return $this->repositoryTokens; 122 132 } 123 133 124 134 private function newURITokensForRepository() { ··· 258 268 259 269 $last_literal = $key; 260 270 } 271 + 272 + $tokens = array_values($tokens); 261 273 262 274 return $tokens; 263 275 }
+38 -3
webroot/rsrc/js/core/behavior-line-linker.js
··· 169 169 JX.History.replace(uri); 170 170 171 171 if (editor_link) { 172 - if (editor_link.href) { 173 - var editdata = JX.Stratcom.getData(editor_link); 174 - editor_link.href = editdata.link_template.replace('%25l', o); 172 + var data = JX.Stratcom.getData(editor_link); 173 + var template = data.template; 174 + 175 + var variables = { 176 + l: parseInt(Math.min(o, t), 10), 177 + }; 178 + 179 + var parts = []; 180 + for (var ii = 0; ii < template.length; ii++) { 181 + var part = template[ii]; 182 + var value = part.value; 183 + 184 + if (part.type === 'literal') { 185 + parts.push(value); 186 + continue; 187 + } 188 + 189 + if (part.type === 'variable') { 190 + if (variables.hasOwnProperty(value)) { 191 + var replacement = variables[value]; 192 + replacement = encodeURIComponent(replacement); 193 + parts.push(replacement); 194 + } 195 + } 175 196 } 197 + 198 + editor_link.href = parts.join(''); 176 199 } 177 200 }); 178 201 ··· 186 209 } catch (ex) { 187 210 // If we didn't hit an element on the page, just move on. 188 211 } 212 + } 213 + 214 + if (editor_link) { 215 + // TODO: This should be pht()'d, but this behavior is weird enough to 216 + // make that a bit tricky. 217 + 218 + new JX.KeyboardShortcut('\\', 'Open File in External Editor') 219 + .setGroup('diff-nav') 220 + .setHandler(function() { 221 + JX.$U(editor_link.href).go(); 222 + }) 223 + .register(); 189 224 } 190 225 191 226 });