Commit 528e126d authored by catch's avatar catch
Browse files

Issue #2823589 by droplet, jungle: Improve IME handling on Autocomplete

parent bd1b3a47
......@@ -77,6 +77,11 @@
*/
function searchHandler(event) {
var options = autocomplete.options;
if (options.isComposing) {
return false;
}
var term = autocomplete.extractLastTerm(event.target.value);
// Abort search if the first character is in firstCharacterBlacklist.
if (term.length > 0 && options.firstCharacterBlacklist.indexOf(term[0]) !== -1) {
......@@ -225,6 +230,14 @@
.each(function () {
$(this).data('ui-autocomplete')._renderItem = autocomplete.options.renderItem;
});
// Use CompositionEvent to handle IME inputs. It requests remote server on "compositionend" event only.
$autocomplete.on('compositionstart.autocomplete', function () {
autocomplete.options.isComposing = true;
});
$autocomplete.on('compositionend.autocomplete', function () {
autocomplete.options.isComposing = false;
});
}
},
detach: function (context, settings, trigger) {
......@@ -261,7 +274,9 @@
renderItem: renderItem,
minLength: 1,
// Custom options, used by Drupal.autocomplete.
firstCharacterBlacklist: ''
firstCharacterBlacklist: '',
// Custom options, indicate IME usage status.
isComposing: false
},
ajax: {
dataType: 'json'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment