From 2d495e97014d2834f76cdff9bc392a16b51428df Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 15 Jan 2016 11:10:38 -0800 Subject: [PATCH] Improve autocomplete behavior when typing ordered lists Summary: Ref T10163. - If a user types an autocomplete character ("@" or "#") and then a space, deactivate immediately (probably an ordered list). - If a user types an autocomplete character indented on a line with no other prior text, don't activate (probably an ordered list or code block). Test Plan: Typed: - `# `, saw immediate deactivation. - ` #`, saw no activation in the first place. - `#x`, saw activation. - `asdf #x`, saw activation. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10163 Differential Revision: https://secure.phabricator.com/D15033 --- resources/celerity/map.php | 6 +++--- webroot/rsrc/js/phuix/PHUIXAutocomplete.js | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index db8912ccf6..dafe3e3166 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' => '3d6e37cc', + 'rsrc/js/phuix/PHUIXAutocomplete.js' => '3dfff01f', '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' => '3d6e37cc', + 'phuix-autocomplete' => '3dfff01f', 'phuix-dropdown-menu' => 'bd4c8dca', 'phuix-form-control-view' => '8fba1997', 'phuix-icon-view' => 'bff6884b', @@ -1080,7 +1080,7 @@ return array( 'javelin-util', 'javelin-uri', ), - '3d6e37cc' => array( + '3dfff01f' => array( 'javelin-install', 'javelin-dom', 'phuix-icon-view', diff --git a/webroot/rsrc/js/phuix/PHUIXAutocomplete.js b/webroot/rsrc/js/phuix/PHUIXAutocomplete.js index 118ae7e293..7df865138b 100644 --- a/webroot/rsrc/js/phuix/PHUIXAutocomplete.js +++ b/webroot/rsrc/js/phuix/PHUIXAutocomplete.js @@ -119,6 +119,16 @@ 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 + // numbered list. + var line = area.value.substring(0, head); + line = line.split('\n'); + line = line[line.length - 1]; + if (line.match(/^\s+/)) { + return; + } + this._cursorHead = head; this._cursorTail = range.end; this._pixelHead = JX.TextAreaUtils.getPixelDimensions( @@ -370,6 +380,13 @@ JX.install('PHUIXAutocomplete', { var x = this._pixelHead.start.x; var y = Math.max(this._pixelHead.end.y, pixels.end.y) + 24; + // If the first character after the trigger is a space, just deactivate + // immediately. This occurs if a user types a numbered list using "#". + if (text.length && text[0] == ' ') { + this._deactivate(); + return; + } + var trim = this._trim(text); this._datasource.didChange(trim);