Skip to content

fix 9790 - ESCAPE in autocomplete should not change multiline value. #1190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/unit/autocomplete/autocomplete_core.js
Original file line number Diff line number Diff line change
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 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the delay is set to 50 you should be able to drop this argument altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied, pasted and modified from the tests above.

});



asyncTest( "handle race condition", function() {
expect( 3 );
var count = 0,
Expand Down
4 changes: 3 additions & 1 deletion ui/autocomplete.js
Original file line number Diff line number Diff line change
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