diff --git a/addons/mail/static/src/js/composer.js b/addons/mail/static/src/js/composer.js index 184f1d66e82..e342074c5bd 100644 --- a/addons/mail/static/src/js/composer.js +++ b/addons/mail/static/src/js/composer.js @@ -145,24 +145,6 @@ var MentionManager = Widget.extend({ return selections; }, - proposition_navigation: function (keycode) { - var $active = this.$('.o_mention_proposition.active'); - if (keycode === $.ui.keyCode.ENTER) { // selecting proposition - $active.click(); - } else { // navigation in propositions - var $to; - if (keycode === $.ui.keyCode.DOWN) { - $to = $active.nextAll('.o_mention_proposition').first(); - } else { - $to = $active.prevAll('.o_mention_proposition').first(); - } - if ($to.length) { - $active.removeClass('active'); - $to.addClass('active'); - } - } - }, - /** * Detects if the user is currently typing a mention word * @return the search string if it is, false otherwise @@ -286,6 +268,32 @@ var MentionManager = Widget.extend({ } return result; }, + /** + * @private + * @param {integer} keycode + */ + _propositionNavigation: function (keycode) { + var $active = this.$('.o_mention_proposition.active'); + if (keycode === $.ui.keyCode.ENTER) { // selecting proposition + $active.click(); + } else { // navigation in propositions + var $to; + if (keycode === $.ui.keyCode.DOWN) { + $to = $active.nextAll('.o_mention_proposition').first(); + } else if (keycode === $.ui.keyCode.UP) { + $to = $active.prevAll('.o_mention_proposition').first(); + } else if (keycode === $.ui.keyCode.TAB) { + $to = $active.nextAll('.o_mention_proposition').first(); + if (!$to.length) { + $to = $active.prevAll('.o_mention_proposition').last(); + } + } + if ($to && $to.length) { + $active.removeClass('active'); + $to.addClass('active'); + } + } + }, _render_suggestions: function () { var suggestions = []; if (_.find(this.get('mention_suggestions'), _.isArray)) { @@ -522,9 +530,10 @@ var BasicComposer = Widget.extend(chat_mixin, { on_keydown: function (event) { switch(event.which) { - // UP, DOWN: prevent moving cursor if navigation in mention propositions + // UP, DOWN, TAB: prevent moving cursor if navigation in mention propositions case $.ui.keyCode.UP: case $.ui.keyCode.DOWN: + case $.ui.keyCode.TAB: if (this.mention_manager.is_open()) { event.preventDefault(); } @@ -560,12 +569,13 @@ var BasicComposer = Widget.extend(chat_mixin, { this.trigger_up("escape_pressed"); } break; - // ENTER, UP, DOWN: check if navigation in mention propositions + // ENTER, UP, DOWN, TAB: check if navigation in mention propositions case $.ui.keyCode.ENTER: case $.ui.keyCode.UP: case $.ui.keyCode.DOWN: + case $.ui.keyCode.TAB: if (this.mention_manager.is_open()) { - this.mention_manager.proposition_navigation(event.which); + this.mention_manager._propositionNavigation(event.which); } break; // Otherwise, check if a mention is typed @@ -814,7 +824,9 @@ var BasicComposer = Widget.extend(chat_mixin, { * @private */ _onEmojiButtonFocusout: function () { - this._hideEmojisTimeout = setTimeout(this._hideEmojis.bind(this), 0); + if (this.$emojisContainer) { + this._hideEmojisTimeout = setTimeout(this._hideEmojis.bind(this), 0); + } }, /** * Called when an emoji is focused -> @see _onEmojiButtonFocusout