Skip to content

Commit 930bc7d

Browse files
Yermoscottgonzalez
authored andcommitted
Autocomplete: ESCAPE should not change content of a MultiLine
Fixes #9790 Closes jquerygh-1190
1 parent 5beae72 commit 930bc7d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

tests/unit/autocomplete/autocomplete_core.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,34 @@ asyncTest( "past end of menu in multiline autocomplete", function() {
189189
}, 50 );
190190
});
191191

192+
asyncTest( "ESCAPE in multiline autocomplete", function() {
193+
expect( 2 );
194+
195+
var customVal = "custom value",
196+
element = $( "#autocomplete-contenteditable" ).autocomplete({
197+
delay: 0,
198+
source: [ "javascript" ],
199+
focus: function( event, ui ) {
200+
equal( ui.item.value, "javascript", "Item gained focus" );
201+
$( this ).text( customVal );
202+
event.preventDefault();
203+
}
204+
});
205+
206+
element
207+
.simulate( "focus" )
208+
.autocomplete( "search", "ja" );
209+
210+
setTimeout(function() {
211+
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
212+
element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
213+
equal( element.text(), customVal );
214+
start();
215+
}, 50 );
216+
});
217+
218+
219+
192220
asyncTest( "handle race condition", function() {
193221
expect( 3 );
194222
var count = 0,

ui/autocomplete.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ $.widget( "ui.autocomplete", {
130130
break;
131131
case keyCode.ESCAPE:
132132
if ( this.menu.element.is( ":visible" ) ) {
133-
this._value( this.term );
133+
if ( !this.isMultiLine ) {
134+
this._value( this.term );
135+
}
134136
this.close( event );
135137
// Different browsers have different default behavior for escape
136138
// Single press can mean undo or clear

0 commit comments

Comments
 (0)