1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

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
This commit is contained in:
epriestley 2020-04-19 07:41:20 -07:00
parent 537ff68edd
commit ef69c7969f
4 changed files with 78 additions and 25 deletions

View file

@ -483,7 +483,7 @@ return array(
'rsrc/js/core/behavior-keyboard-pager.js' => '1325b731', 'rsrc/js/core/behavior-keyboard-pager.js' => '1325b731',
'rsrc/js/core/behavior-keyboard-shortcuts.js' => '42c44e8b', 'rsrc/js/core/behavior-keyboard-shortcuts.js' => '42c44e8b',
'rsrc/js/core/behavior-lightbox-attachments.js' => 'c7e748bf', 'rsrc/js/core/behavior-lightbox-attachments.js' => 'c7e748bf',
'rsrc/js/core/behavior-line-linker.js' => 'e15c8b1f', 'rsrc/js/core/behavior-line-linker.js' => '590e6527',
'rsrc/js/core/behavior-linked-container.js' => '74446546', 'rsrc/js/core/behavior-linked-container.js' => '74446546',
'rsrc/js/core/behavior-more.js' => '506aa3f4', 'rsrc/js/core/behavior-more.js' => '506aa3f4',
'rsrc/js/core/behavior-object-selector.js' => '98ef467f', 'rsrc/js/core/behavior-object-selector.js' => '98ef467f',
@ -644,7 +644,7 @@ return array(
'javelin-behavior-phabricator-gesture-example' => '242dedd0', 'javelin-behavior-phabricator-gesture-example' => '242dedd0',
'javelin-behavior-phabricator-keyboard-pager' => '1325b731', 'javelin-behavior-phabricator-keyboard-pager' => '1325b731',
'javelin-behavior-phabricator-keyboard-shortcuts' => '42c44e8b', 'javelin-behavior-phabricator-keyboard-shortcuts' => '42c44e8b',
'javelin-behavior-phabricator-line-linker' => 'e15c8b1f', 'javelin-behavior-phabricator-line-linker' => '590e6527',
'javelin-behavior-phabricator-nav' => 'f166c949', 'javelin-behavior-phabricator-nav' => 'f166c949',
'javelin-behavior-phabricator-notification-example' => '29819b75', 'javelin-behavior-phabricator-notification-example' => '29819b75',
'javelin-behavior-phabricator-object-selector' => '98ef467f', 'javelin-behavior-phabricator-object-selector' => '98ef467f',
@ -1452,6 +1452,12 @@ return array(
'javelin-util', 'javelin-util',
'javelin-magical-init', 'javelin-magical-init',
), ),
'590e6527' => array(
'javelin-behavior',
'javelin-stratcom',
'javelin-dom',
'javelin-history',
),
'5a4e4a3b' => array( '5a4e4a3b' => array(
'javelin-dom', 'javelin-dom',
'javelin-util', 'javelin-util',
@ -2096,12 +2102,6 @@ return array(
'javelin-dom', 'javelin-dom',
'phuix-dropdown-menu', 'phuix-dropdown-menu',
), ),
'e15c8b1f' => array(
'javelin-behavior',
'javelin-stratcom',
'javelin-dom',
'javelin-history',
),
'e5bdb730' => array( 'e5bdb730' => array(
'javelin-behavior', 'javelin-behavior',
'javelin-stratcom', 'javelin-stratcom',

View file

@ -472,15 +472,21 @@ final class DiffusionBrowseController extends DiffusionController {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$base_uri = $this->getRequest()->getRequestURI(); $base_uri = $this->getRequest()->getRequestURI();
$user = $this->getRequest()->getUser();
$repository = $drequest->getRepository(); $repository = $drequest->getRepository();
$path = $drequest->getPath(); $path = $drequest->getPath();
$line = nonempty((int)$drequest->getLine(), 1); $line = nonempty((int)$drequest->getLine(), 1);
$buttons = array(); $buttons = array();
// TODO: Restore these behaviors. $editor_uri = null;
$editor_link = null; $editor_template = null;
$template = null;
$link_engine = PhabricatorEditorURIEngine::newForViewer($viewer);
if ($link_engine) {
$link_engine->setRepository($repository);
$editor_uri = $link_engine->getURIForPath($path, $line);
$editor_template = $link_engine->getURITokensForPath($path);
}
$buttons[] = $buttons[] =
id(new PHUIButtonView()) id(new PHUIButtonView())
@ -494,16 +500,16 @@ final class DiffusionBrowseController extends DiffusionController {
))) )))
->setIcon('fa-backward'); ->setIcon('fa-backward');
if ($editor_link) { if ($editor_uri) {
$buttons[] = $buttons[] =
id(new PHUIButtonView()) id(new PHUIButtonView())
->setTag('a') ->setTag('a')
->setText(pht('Open File')) ->setText(pht('Open File'))
->setHref($editor_link) ->setHref($editor_uri)
->setIcon('fa-pencil') ->setIcon('fa-pencil')
->setID('editor_link') ->setID('editor_link')
->setMetadata(array('link_template' => $template)) ->setMetadata(array('template' => $editor_template))
->setDisabled(!$editor_link) ->setDisabled(!$editor_uri)
->setColor(PHUIButtonView::GREY); ->setColor(PHUIButtonView::GREY);
} }

View file

@ -68,7 +68,7 @@ final class PhabricatorEditorURIEngine
} }
public function getURIForPath($path, $line) { public function getURIForPath($path, $line) {
$tokens = $this->getURITokensForRepository(); $tokens = $this->getURITokensForRepository($path);
$variables = array( $variables = array(
'f' => $this->escapeToken($path), 'f' => $this->escapeToken($path),
@ -80,12 +80,14 @@ final class PhabricatorEditorURIEngine
return $this->newStringFromTokens($tokens); return $this->newStringFromTokens($tokens);
} }
public function getURITokensForRepository() { public function getURITokensForPath($path) {
if (!$this->repositoryTokens) { $tokens = $this->getURITokensForRepository($path);
$this->repositoryTokens = $this->newURITokensForRepository();
}
return $this->repositoryTokens; $variables = array(
'f' => $this->escapeToken($path),
);
return $this->newTokensWithVariables($tokens, $variables);
} }
public static function getVariableDefinitions() { public static function getVariableDefinitions() {
@ -121,6 +123,14 @@ final class PhabricatorEditorURIEngine
); );
} }
private function getURITokensForRepository() {
if (!$this->repositoryTokens) {
$this->repositoryTokens = $this->newURITokensForRepository();
}
return $this->repositoryTokens;
}
private function newURITokensForRepository() { private function newURITokensForRepository() {
$tokens = $this->getRawURITokens(); $tokens = $this->getRawURITokens();
@ -259,6 +269,8 @@ final class PhabricatorEditorURIEngine
$last_literal = $key; $last_literal = $key;
} }
$tokens = array_values($tokens);
return $tokens; return $tokens;
} }

View file

@ -169,10 +169,33 @@ JX.behavior('phabricator-line-linker', function() {
JX.History.replace(uri); JX.History.replace(uri);
if (editor_link) { if (editor_link) {
if (editor_link.href) { var data = JX.Stratcom.getData(editor_link);
var editdata = JX.Stratcom.getData(editor_link); var template = data.template;
editor_link.href = editdata.link_template.replace('%25l', o);
var variables = {
l: parseInt(Math.min(o, t), 10),
};
var parts = [];
for (var ii = 0; ii < template.length; ii++) {
var part = template[ii];
var value = part.value;
if (part.type === 'literal') {
parts.push(value);
continue;
}
if (part.type === 'variable') {
if (variables.hasOwnProperty(value)) {
var replacement = variables[value];
replacement = encodeURIComponent(replacement);
parts.push(replacement);
}
}
} }
editor_link.href = parts.join('');
} }
}); });
@ -188,4 +211,16 @@ JX.behavior('phabricator-line-linker', function() {
} }
} }
if (editor_link) {
// TODO: This should be pht()'d, but this behavior is weird enough to
// make that a bit tricky.
new JX.KeyboardShortcut('\\', 'Open File in External Editor')
.setGroup('diff-nav')
.setHandler(function() {
JX.$U(editor_link.href).go();
})
.register();
}
}); });