Elastic: Fix duplicate recipient after using Tab key in recipient input (regression)

pull/6476/merge
Aleksander Machniak 6 years ago
parent b126941846
commit 38255ff52a

@ -2796,7 +2796,7 @@ function rcube_elastic_ui()
*/ */
function recipient_input(obj) function recipient_input(obj)
{ {
var list, input, ac_props, var list, input, ac_props, update_lock,
input_len_update = function() { input_len_update = function() {
input.css('width', input.val().length * 10 + 15); input.css('width', input.val().length * 10 + 15);
}, },
@ -2839,6 +2839,12 @@ function rcube_elastic_ui()
update_func = function(text) { update_func = function(text) {
var result; var result;
if (update_lock) {
return;
}
update_lock = true;
text = (text || input.val()).replace(/[,;\s]+$/, ''); text = (text || input.val()).replace(/[,;\s]+$/, '');
result = recipient_input_parser(text); result = recipient_input_parser(text);
@ -2847,28 +2853,24 @@ function rcube_elastic_ui()
}); });
// setTimeout() here is needed for proper input reset on paste event // setTimeout() here is needed for proper input reset on paste event
// This is also the reason why we need parse_lock
setTimeout(function() { setTimeout(function() {
input.val(result.text); input.val(result.text);
apply_func(); apply_func();
input_len_update(); input_len_update();
update_lock = false;
}, 1); }, 1);
return result.recipients.length > 0; return result.recipients.length > 0;
}, },
parse_func = function(e) { parse_func = function(e) {
// On paste the text is not yet in the input we have to use clipboard.
// Also because on paste new-line characters are replaced by spaces (#6460)
if (e.type == 'paste') {
update_func((e.originalEvent.clipboardData || window.clipboardData).getData('text'));
return;
}
// Note: it can be also executed when autocomplete inserts a recipient
update_func();
if (e.type == 'blur') { if (e.type == 'blur') {
list.removeClass('focus'); list.removeClass('focus');
} }
// On paste the text is not yet in the input we have to use clipboard.
// Also because on paste new-line characters are replaced by spaces (#6460)
update_func(e.type == 'paste' ? (e.originalEvent.clipboardData || window.clipboardData).getData('text') : null);
}, },
keydown_func = function(e) { keydown_func = function(e) {
// On Backspace remove the last recipient // On Backspace remove the last recipient

Loading…
Cancel
Save