From 4a0d3ba3e14b65ae88131c87e1b1ce0dd9b927c8 Mon Sep 17 00:00:00 2001 From: Valerio Bozzolan Date: Tue, 4 Jul 2023 17:10:19 +0200 Subject: [PATCH] Locate File: allow to search './path/to/something.txt' Summary: Before this change, if you search a file using Locate File, this was the only accepted syntax for a full-path: path/to/something.txt After this change, some relative/absolute Unix-like variants are also accepted: ./path/to/something.txt /path/to/something.txt Similar prefixes can be frequent when you quickly copy-paste things from shell commands like 'grep' or 'find' etc. Ref T15508 Test Plan: Visit a lovely repository like Phorge and use Locate File with these: 1. src/applications/maniphest/editor/ManiphestEditEngine.php 2. /src/applications/maniphest/editor/ManiphestEditEngine.php 3. ./src/applications/maniphest/editor/ManiphestEditEngine.php After this change, also 2. and 3. return the expected file. Reviewers: O1 Blessed Committers, avivey Reviewed By: O1 Blessed Committers, avivey Subscribers: avivey, speck, tobiaswiese, Matthew, Cigaryno Maniphest Tasks: T15508 Differential Revision: https://we.phorge.it/D25320 --- resources/celerity/map.php | 16 ++++++++-------- .../diffusion/DiffusionLocateFileSource.js | 4 ++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 277db4a5b7..0f0ee9d3f4 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -387,7 +387,7 @@ return array( 'rsrc/js/application/diff/DiffTreeView.js' => '5d83623b', 'rsrc/js/application/differential/behavior-diff-radios.js' => '925fe8cd', 'rsrc/js/application/differential/behavior-populate.js' => 'b86ef6c2', - 'rsrc/js/application/diffusion/DiffusionLocateFileSource.js' => '94243d89', + 'rsrc/js/application/diffusion/DiffusionLocateFileSource.js' => '6c798a10', 'rsrc/js/application/diffusion/ExternalEditorLinkEngine.js' => '48a8641f', 'rsrc/js/application/diffusion/behavior-audit-preview.js' => 'b7b73831', 'rsrc/js/application/diffusion/behavior-commit-branches.js' => '4b671572', @@ -707,7 +707,7 @@ return array( 'javelin-chart-function-label' => '81de1dab', 'javelin-color' => '78f811c9', 'javelin-cookie' => '05d290ef', - 'javelin-diffusion-locate-file-source' => '94243d89', + 'javelin-diffusion-locate-file-source' => '6c798a10', 'javelin-dom' => 'e4c7622a', 'javelin-dynval' => '202a2e85', 'javelin-event' => 'c03f2fb4', @@ -1555,6 +1555,12 @@ return array( 'phabricator-textareautils', 'phabricator-remarkup-metadata', ), + '6c798a10' => array( + 'javelin-install', + 'javelin-dom', + 'javelin-typeahead-preloaded-source', + 'javelin-util', + ), '6cfa0008' => array( 'javelin-dom', 'javelin-dynval', @@ -1762,12 +1768,6 @@ return array( 'phabricator-prefab', 'javelin-json', ), - '94243d89' => array( - 'javelin-install', - 'javelin-dom', - 'javelin-typeahead-preloaded-source', - 'javelin-util', - ), '9623adc1' => array( 'javelin-behavior', 'javelin-stratcom', diff --git a/webroot/rsrc/js/application/diffusion/DiffusionLocateFileSource.js b/webroot/rsrc/js/application/diffusion/DiffusionLocateFileSource.js index 1f94f349d3..3a3bcb9bce 100644 --- a/webroot/rsrc/js/application/diffusion/DiffusionLocateFileSource.js +++ b/webroot/rsrc/js/application/diffusion/DiffusionLocateFileSource.js @@ -99,6 +99,10 @@ JX.install('DiffusionLocateFileSource', { return []; } + // Be nice with terminal users that may have "./" or "/" prefixes. + // Otherwise, not a single result is returned. + search = search.replace(/^\.?\//, ''); + // We know that the results for "abc" are always a subset of the results // for "a" and "ab" -- and there's a good chance we already computed // those result sets. Find the longest cached result which is a prefix