@@ -229,18 +229,23 @@ class Autocomplete {
229229 // We use this method instead of the `focusout` event because this way it's
230230 // easier to work in the developer tools when you want to inspect the element.
231231 // When you inspect it, a `focusout` happens.
232- this . popup . hide ( ) ;
232+ this . hidePopup ( 'The user clicked away' ) ;
233233 this . input = null ;
234234 }
235235 }
236236
237+ hidePopup ( reason : string ) {
238+ this . serverSideTagSuggestions . abortLastSchedule ( `[Autocomplete] Popup was hidden. ${ reason } ` ) ;
239+ this . popup . hide ( ) ;
240+ }
241+
237242 onKeyDown ( event : KeyboardEvent ) {
238243 if ( ! this . isActive ( ) || this . input . element !== event . target ) {
239244 return ;
240245 }
241246 if ( ( event . key === ',' || event . code === 'Enter' ) && this . input . type === 'single-tag' ) {
242- // Coma means the end of input for the current tag in single-tag mode.
243- this . popup . hide ( ) ;
247+ // Comma/Enter mean the end of input for the current tag in single-tag mode.
248+ this . hidePopup ( `The user accepted the existing input via key: ' ${ event . key } ', code: ' ${ event . code } '` ) ;
244249 return ;
245250 }
246251
@@ -265,7 +270,7 @@ class Autocomplete {
265270 return ;
266271 }
267272 case 'Escape' : {
268- this . popup . hide ( ) ;
273+ this . hidePopup ( 'User pressed "Escape"' ) ;
269274 return ;
270275 }
271276 case 'ArrowLeft' :
@@ -340,7 +345,14 @@ class Autocomplete {
340345 // brief moment of silence for the user without the popup before they type
341346 // something else, otherwise we'd show some more completions for the current term.
342347 this . input . element . focus ( ) ;
343- this . popup . hide ( ) ;
348+
349+ // Technically no server-side suggestion request can be in flight at this point.
350+ // If the user managed to accept a suggestion, it means the user already got
351+ // presented with the results of auto-completions, so there is nothing in-flight.
352+ //
353+ // Although, we don't make this a hard assertion just in case, to make sure this
354+ // code is tolerant to any bugs in the described assumption.
355+ this . hidePopup ( 'The user accepted the existing suggestion' ) ;
344356 }
345357
346358 updateInputWithSelectedValue ( this : ActiveAutocomplete , suggestion : Suggestion ) {
0 commit comments