Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Autocomplete: ESCAPE should not change content of a MultiLine
Fixes #9790
Closes gh-1190
  • Loading branch information
Yermo authored and scottgonzalez committed Jul 24, 2014
1 parent 5beae72 commit 930bc7d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 28 additions & 0 deletions tests/unit/autocomplete/autocomplete_core.js
Expand Up @@ -189,6 +189,34 @@ asyncTest( "past end of menu in multiline autocomplete", function() {
}, 50 );
});

asyncTest( "ESCAPE in multiline autocomplete", function() {
expect( 2 );

var customVal = "custom value",
element = $( "#autocomplete-contenteditable" ).autocomplete({
delay: 0,
source: [ "javascript" ],
focus: function( event, ui ) {
equal( ui.item.value, "javascript", "Item gained focus" );
$( this ).text( customVal );
event.preventDefault();
}
});

element
.simulate( "focus" )
.autocomplete( "search", "ja" );

setTimeout(function() {
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
equal( element.text(), customVal );
start();
}, 50 );
});



asyncTest( "handle race condition", function() {
expect( 3 );
var count = 0,
Expand Down
4 changes: 3 additions & 1 deletion ui/autocomplete.js
Expand Up @@ -130,7 +130,9 @@ $.widget( "ui.autocomplete", {
break;
case keyCode.ESCAPE:
if ( this.menu.element.is( ":visible" ) ) {
this._value( this.term );
if ( !this.isMultiLine ) {
this._value( this.term );
}
this.close( event );
// Different browsers have different default behavior for escape
// Single press can mean undo or clear
Expand Down

0 comments on commit 930bc7d

Please sign in to comment.