From 75781dba1add1f2be3510bbd87a9df41f60b0ac9 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 16 Jan 2016 14:59:17 -0800 Subject: [PATCH] Improve autocomplete behavior in lists and with noncompleting results Summary: Ref T10163. Currently, we don't activate on indented lines, but were too aggressive about this, and would not activate on lines like ` - Hey, @user...`, where we should. Instead, don't activate on indented lines if there's only an indent (i.e., `#` probably means enumerated list). Also, if results don't have autocompletes (rare but possible with projects missing slugs), improve behavior. Test Plan: - Typed ` #a`, got no autocomplete. - Missing slug thing is a pain to test locallly, `#1 z z z z` reproduces in production. I'll just verify it there. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10163 Differential Revision: https://secure.phabricator.com/D15040 --- resources/celerity/map.php | 16 ++++++++-------- webroot/rsrc/js/phuix/PHUIXAutocomplete.js | 13 +++++++++---- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 3dec5a890b..8f22b91818 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -507,7 +507,7 @@ return array( 'rsrc/js/phui/behavior-phui-object-box-tabs.js' => '2bfa2836', 'rsrc/js/phuix/PHUIXActionListView.js' => 'b5c256b8', 'rsrc/js/phuix/PHUIXActionView.js' => '8cf6d262', - 'rsrc/js/phuix/PHUIXAutocomplete.js' => '0abdd4a8', + 'rsrc/js/phuix/PHUIXAutocomplete.js' => '8bbbad27', 'rsrc/js/phuix/PHUIXDropdownMenu.js' => 'bd4c8dca', 'rsrc/js/phuix/PHUIXFormControl.js' => '8fba1997', 'rsrc/js/phuix/PHUIXIconView.js' => 'bff6884b', @@ -836,7 +836,7 @@ return array( 'phui-workpanel-view-css' => 'adec7699', 'phuix-action-list-view' => 'b5c256b8', 'phuix-action-view' => '8cf6d262', - 'phuix-autocomplete' => '0abdd4a8', + 'phuix-autocomplete' => '8bbbad27', 'phuix-dropdown-menu' => 'bd4c8dca', 'phuix-form-control-view' => '8fba1997', 'phuix-icon-view' => 'bff6884b', @@ -917,12 +917,6 @@ return array( 'javelin-dom', 'javelin-router', ), - '0abdd4a8' => array( - 'javelin-install', - 'javelin-dom', - 'phuix-icon-view', - 'phabricator-prefab', - ), '0b7a4f6e' => array( 'javelin-behavior', 'javelin-typeahead-ondemand-source', @@ -1495,6 +1489,12 @@ return array( 'javelin-stratcom', 'javelin-vector', ), + '8bbbad27' => array( + 'javelin-install', + 'javelin-dom', + 'phuix-icon-view', + 'phabricator-prefab', + ), '8bdb2835' => array( 'phui-fontkit-css', ), diff --git a/webroot/rsrc/js/phuix/PHUIXAutocomplete.js b/webroot/rsrc/js/phuix/PHUIXAutocomplete.js index d34909c44f..b94688e086 100644 --- a/webroot/rsrc/js/phuix/PHUIXAutocomplete.js +++ b/webroot/rsrc/js/phuix/PHUIXAutocomplete.js @@ -127,13 +127,13 @@ JX.install('PHUIXAutocomplete', { return; } - // Get all the text on the current line. If the line begins with - // whitespace, don't activate: the user is probably typing code or a + // Get all the text on the current line. If the line only contains + // whitespace, don't actiavte: the user is probably typing code or a // numbered list. - var line = area.value.substring(0, head); + var line = area.value.substring(0, head - 1); line = line.split('\n'); line = line[line.length - 1]; - if (line.match(/^\s+/)) { + if (line.match(/^\s+$/)) { return; } @@ -223,6 +223,11 @@ JX.install('PHUIXAutocomplete', { break; } + if (!result.autocomplete || !result.autocomplete.length) { + hits = null; + break; + } + hits.push(result.autocomplete); }