From 48001a8c46adc5d1d6c1726cecbe6453946e96e0 Mon Sep 17 00:00:00 2001 From: TJ VanToll Date: Thu, 1 May 2014 09:57:38 -0400 Subject: [PATCH] Autocomplete: Search if the user retypes the same value Fixes #7434 Closes gh-1238 --- tests/unit/autocomplete/autocomplete_core.js | 21 ++++++++++++++++++++ ui/autocomplete.js | 9 +++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/unit/autocomplete/autocomplete_core.js b/tests/unit/autocomplete/autocomplete_core.js index 2a901006b..c306495f2 100644 --- a/tests/unit/autocomplete/autocomplete_core.js +++ b/tests/unit/autocomplete/autocomplete_core.js @@ -338,4 +338,25 @@ test( ".replaceWith() (#9172)", function() { equal( parent.html().toLowerCase(), replacement ); }); +asyncTest( "Search if the user retypes the same value (#7434)", function() { + expect( 3 ); + var element = $( "#autocomplete" ).autocomplete({ + source: [ "java", "javascript" ], + delay: 0 + }), + menu = element.autocomplete( "instance" ).menu.element; + + element.val( "j" ).simulate( "keydown" ); + setTimeout(function() { + ok( menu.is( ":visible" ), "menu displays initially" ); + element.trigger( "blur" ); + ok( !menu.is( ":visible" ), "menu hidden after blur" ); + element.val( "j" ).simulate( "keydown" ); + setTimeout(function() { + ok( menu.is( ":visible" ), "menu displays after typing the same value" ); + start(); + }); + }); +}); + }( jQuery ) ); diff --git a/ui/autocomplete.js b/ui/autocomplete.js index 10de5dc19..d53a1d5e3 100644 --- a/ui/autocomplete.js +++ b/ui/autocomplete.js @@ -394,8 +394,13 @@ $.widget( "ui.autocomplete", { _searchTimeout: function( event ) { clearTimeout( this.searching ); this.searching = this._delay(function() { - // only search if the value has changed - if ( this.term !== this._value() ) { + + // Search if the value has changed, or if the user retypes the same value (see #7434) + var equalValues = this.term === this._value(), + menuVisible = this.menu.element.is( ":visible" ), + modifierKey = event.altKey || event.ctrlKey || event.metaKey || event.shiftKey; + + if ( !equalValues || ( equalValues && !menuVisible && !modifierKey ) ) { this.selectedItem = null; this.search( null, event ); } -- 2.39.5