From adb1d3a5be6845ffe987e033171adc64ef1f66e8 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 26 Apr 2017 08:37:29 -0700 Subject: [PATCH] Fix autocomplete/send-on-enter interactions Summary: Send-on-enter and autocomplete both listen for "return" keypresses, and could race. Have autocomplete let other handlers take a shot at the action before it does. Also, fix a case where ":)" and the suffix list (which lets you type `someone is 100% to blame here (@epriestley)` and get the results you want) interacted badly, so ":)" cancels the autocompleter like ":3" does. Test Plan: - Typed "@xxx" and mashed return real fast over and over again while reloading the page. Before: sometimes handlers raced and text submitted. After: always handled by autocomplete behavior. - Typed ":", ")", "", sent an emoticon (previously: no). Reviewers: chad, amckinley Reviewed By: chad Subscribers: xxx Differential Revision: https://secure.phabricator.com/D17794 --- .../js/core/behavior-phabricator-remarkup-assist.js | 9 +++++++-- webroot/rsrc/js/phuix/PHUIXAutocomplete.js | 10 +++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/webroot/rsrc/js/core/behavior-phabricator-remarkup-assist.js b/webroot/rsrc/js/core/behavior-phabricator-remarkup-assist.js index a53c567607..e4d987c425 100644 --- a/webroot/rsrc/js/core/behavior-phabricator-remarkup-assist.js +++ b/webroot/rsrc/js/core/behavior-phabricator-remarkup-assist.js @@ -393,6 +393,12 @@ JX.behavior('phabricator-remarkup-assist', function(config) { return; } + // Let other listeners (particularly the inline autocomplete) have a + // chance to handle this event. + if (JX.Stratcom.pass()) { + return; + } + var raw = e.getRawEvent(); if (raw.shiftKey) { // If the shift key is pressed, let the browser write a newline into @@ -412,8 +418,7 @@ JX.behavior('phabricator-remarkup-assist', function(config) { // This allows 'workflow' and similar actions to take effect. // Such as pontificate in Conpherence var form = e.getNode('tag:form'); - var r = JX.DOM.invoke(form, 'didSyntheticSubmit'); - + JX.DOM.invoke(form, 'didSyntheticSubmit'); }); } diff --git a/webroot/rsrc/js/phuix/PHUIXAutocomplete.js b/webroot/rsrc/js/phuix/PHUIXAutocomplete.js index 16ed8b75f3..ac073a0e38 100644 --- a/webroot/rsrc/js/phuix/PHUIXAutocomplete.js +++ b/webroot/rsrc/js/phuix/PHUIXAutocomplete.js @@ -127,7 +127,7 @@ JX.install('PHUIXAutocomplete', { } // 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 + // whitespace, don't activate: the user is probably typing code or a // numbered list. var line = area.value.substring(0, head - 1); line = line.split('\n'); @@ -454,7 +454,7 @@ JX.install('PHUIXAutocomplete', { // 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 + // 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(); @@ -529,9 +529,13 @@ JX.install('PHUIXAutocomplete', { } } + // Deactivate immediately if the user types an ignored token like ":)", + // the smiley face emoticon. Note that we test against "text", not + // "trim", because the ignore list and suffix list can otherwise + // interact destructively. var ignore = this._getIgnoreList(); for (ii = 0; ii < ignore.length; ii++) { - if (trim.indexOf(ignore[ii]) === 0) { + if (text.indexOf(ignore[ii]) === 0) { this._deactivate(); return; } -- 2.51.2