diff options
author | meh-cfl <meh@corefiling.co.uk> | 2011-11-28 16:33:23 -0500 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-11-28 16:33:23 -0500 |
commit | 06f6fa8524a905ec8027b8ba756eb199f2591336 (patch) | |
tree | 7fc6068ad10948b4a1ebe319f5d7c2d14d212fdc /ui/jquery.ui.autocomplete.js | |
parent | 74a3f2ce0897ce8bdcac2acc997e68e3e8603121 (diff) | |
download | jquery-ui-06f6fa8524a905ec8027b8ba756eb199f2591336.tar.gz jquery-ui-06f6fa8524a905ec8027b8ba756eb199f2591336.zip |
Autocomplete: Don't invoke a search from arrow keys when the element can have multi-line text. Fixes #7639 - Key up/key down in textarea's should optionally not toggle auto-complete.
Diffstat (limited to 'ui/jquery.ui.autocomplete.js')
-rw-r--r-- | ui/jquery.ui.autocomplete.js | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index dbda2058e..bd415aa2b 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -58,6 +58,7 @@ $.widget( "ui.autocomplete", { suppressKeyPressRepeat, suppressInput; + this.isMultiLine = this.element.is( "textarea,[contenteditable]" ); this.valueMethod = this.element[ this.element.is( "input,textarea" ) ? "val" : "text" ]; this.element @@ -92,15 +93,11 @@ $.widget( "ui.autocomplete", { break; case keyCode.UP: suppressKeyPress = true; - self._move( "previous", event ); - // prevent moving cursor to beginning of text field in some browsers - event.preventDefault(); + self._keyEvent( "previous", event ); break; case keyCode.DOWN: suppressKeyPress = true; - self._move( "next", event ); - // prevent moving cursor to end of text field in some browsers - event.preventDefault(); + self._keyEvent( "next", event ); break; case keyCode.ENTER: case keyCode.NUMPAD_ENTER: @@ -151,14 +148,10 @@ $.widget( "ui.autocomplete", { self._move( "nextPage", event ); break; case keyCode.UP: - self._move( "previous", event ); - // prevent moving cursor to beginning of text field in some browsers - event.preventDefault(); + self._keyEvent( "previous", event ); break; case keyCode.DOWN: - self._move( "next", event ); - // prevent moving cursor to end of text field in some browsers - event.preventDefault(); + self._keyEvent( "next", event ); break; } }) @@ -495,6 +488,15 @@ $.widget( "ui.autocomplete", { _value: function( value ) { return this.valueMethod.apply( this.element, arguments ); + }, + + _keyEvent: function( keyEvent, event ) { + if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) { + this._move( keyEvent, event ); + + // prevents moving cursor to beginning/end of the text field in some browsers + event.preventDefault(); + } } }); |