From 130ebd2c421a0bd0ae0f84ab60acc00ff0436850 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 30 Mar 2017 08:32:41 -0700 Subject: [PATCH] Immediately deactivate remarkup autocomplete if there's no query Summary: Fixes T12479. If you end a line with a character like ":" in a context which can trigger autocomplete (e.g., `.:`), then try to make a newline, we swallow the keystroke. Instead, allow the keystroke through if the user hasn't typed anything else yet. Test Plan: - Autocompleted emoji and users normally. - In an empty textarea, typed `.:`, got a newline instead of a swallowed keystroke. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12479 Differential Revision: https://secure.phabricator.com/D17583 --- resources/celerity/map.php | 16 ++++++------ webroot/rsrc/js/phuix/PHUIXAutocomplete.js | 29 ++++++++++++++-------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index f83c2b0f09..6bee132238 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -528,7 +528,7 @@ return array( 'rsrc/js/phui/behavior-phui-tab-group.js' => '0a0b10e9', 'rsrc/js/phuix/PHUIXActionListView.js' => 'b5c256b8', 'rsrc/js/phuix/PHUIXActionView.js' => 'b3465b9b', - 'rsrc/js/phuix/PHUIXAutocomplete.js' => '7910aacb', + 'rsrc/js/phuix/PHUIXAutocomplete.js' => 'd5b2abf3', 'rsrc/js/phuix/PHUIXDropdownMenu.js' => '8018ee50', 'rsrc/js/phuix/PHUIXFormControl.js' => '83e03671', 'rsrc/js/phuix/PHUIXIconView.js' => 'bff6884b', @@ -885,7 +885,7 @@ return array( 'phui-workpanel-view-css' => 'a3a63478', 'phuix-action-list-view' => 'b5c256b8', 'phuix-action-view' => 'b3465b9b', - 'phuix-autocomplete' => '7910aacb', + 'phuix-autocomplete' => 'd5b2abf3', 'phuix-dropdown-menu' => '8018ee50', 'phuix-form-control-view' => '83e03671', 'phuix-icon-view' => 'bff6884b', @@ -1456,12 +1456,6 @@ return array( 'multirow-row-manager', 'javelin-json', ), - '7910aacb' => array( - 'javelin-install', - 'javelin-dom', - 'phuix-icon-view', - 'phabricator-prefab', - ), '7927a7d3' => array( 'javelin-behavior', 'javelin-quicksand', @@ -2053,6 +2047,12 @@ return array( 'javelin-uri', 'phabricator-notification', ), + 'd5b2abf3' => array( + 'javelin-install', + 'javelin-dom', + 'phuix-icon-view', + 'phabricator-prefab', + ), 'd6a7e717' => array( 'multirow-row-manager', 'javelin-install', diff --git a/webroot/rsrc/js/phuix/PHUIXAutocomplete.js b/webroot/rsrc/js/phuix/PHUIXAutocomplete.js index e99dcc34f2..a03c2adf70 100644 --- a/webroot/rsrc/js/phuix/PHUIXAutocomplete.js +++ b/webroot/rsrc/js/phuix/PHUIXAutocomplete.js @@ -433,6 +433,16 @@ JX.install('PHUIXAutocomplete', { } } + // Deactivate if the user moves the cursor to the left of the assist + // range. For example, they might press the "left" arrow to move the + // cursor to the left, or click in the textarea prior to the active + // range. + var range = JX.TextAreaUtils.getSelectionRange(area); + if (range.start < this._cursorHead) { + this._deactivate(); + return; + } + if (special == 'tab' || special == 'return') { var r = e.getRawEvent(); if (r.shiftKey && special == 'tab') { @@ -443,6 +453,15 @@ JX.install('PHUIXAutocomplete', { return; } + // If the user hasn't typed any text yet after typing the character + // which can summon the autocomplete, deactivate and let the keystroke + // through. For example, We hit this when a line ends with an + // autocomplete character and the user is trying to type a newline. + if (range.start == this._cursorHead) { + this._deactivate(); + return; + } + // If we autocomplete, we're done. Otherwise, just eat the event. This // happens if you type too fast and try to tab complete before results // load. @@ -454,16 +473,6 @@ JX.install('PHUIXAutocomplete', { return; } - // Deactivate if the user moves the cursor to the left of the assist - // range. For example, they might press the "left" arrow to move the - // cursor to the left, or click in the textarea prior to the active - // range. - var range = JX.TextAreaUtils.getSelectionRange(area); - if (range.start < this._cursorHead) { - this._deactivate(); - return; - } - // Deactivate if the user moves the cursor to the right of the assist // range. For example, they might click later in the document. If the user // is pressing the "right" arrow key, they are not allowed to move the