From 38255ff52a9df7f009343bfd913b2b9e4f59f068 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sat, 6 Oct 2018 11:29:57 +0200 Subject: [PATCH] Elastic: Fix duplicate recipient after using Tab key in recipient input (regression) --- skins/elastic/ui.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/skins/elastic/ui.js b/skins/elastic/ui.js index 3ca049f99..e4b62b846 100644 --- a/skins/elastic/ui.js +++ b/skins/elastic/ui.js @@ -2796,7 +2796,7 @@ function rcube_elastic_ui() */ function recipient_input(obj) { - var list, input, ac_props, + var list, input, ac_props, update_lock, input_len_update = function() { input.css('width', input.val().length * 10 + 15); }, @@ -2839,6 +2839,12 @@ function rcube_elastic_ui() update_func = function(text) { var result; + if (update_lock) { + return; + } + + update_lock = true; + text = (text || input.val()).replace(/[,;\s]+$/, ''); result = recipient_input_parser(text); @@ -2847,28 +2853,24 @@ function rcube_elastic_ui() }); // setTimeout() here is needed for proper input reset on paste event + // This is also the reason why we need parse_lock setTimeout(function() { input.val(result.text); apply_func(); input_len_update(); + update_lock = false; }, 1); return result.recipients.length > 0; }, 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') { 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) { // On Backspace remove the last recipient