From dfafbefb712e1bf096050ef62854eabf0fefd7f7 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Thu, 5 Sep 2019 16:22:57 +0200 Subject: [PATCH] emoji-view: insert partially matched emoji on enter if it's the only search hit. --- src/converse-emoji-views.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/converse-emoji-views.js b/src/converse-emoji-views.js index 25e300a49..9f9557d47 100644 --- a/src/converse-emoji-views.js +++ b/src/converse-emoji-views.js @@ -239,6 +239,15 @@ converse.plugins.add('converse-emoji-views', { sizzle('.emoji-picker', this.el).forEach(a => this.observer.observe(a)); }, + insertIntoTextArea (value) { + const replace = this.model.get('autocompleting'); + const position = this.model.get('position'); + this.model.set({'autocompleting': null, 'position': null}); + this.chatview.insertIntoTextArea(value, replace, false, position); + this.chatview.emoji_dropdown.toggle(); + this.filter('', true); + }, + onKeyDown (ev) { if (ev.keyCode === _converse.keycodes.TAB) { ev.preventDefault(); @@ -250,12 +259,9 @@ converse.plugins.add('converse-emoji-views', { ev.preventDefault(); ev.stopPropagation(); if (_converse.emoji_shortnames.includes(ev.target.value)) { - const replace = this.model.get('autocompleting'); - const position = this.model.get('position'); - this.model.set({'autocompleting': null, 'position': null}); - this.chatview.insertIntoTextArea(ev.target.value, replace, false, position); - this.chatview.emoji_dropdown.toggle(); - this.filter('', true); + this.insertIntoTextArea(ev.target.value); + } else if (this.search_results.length === 1) { + this.insertIntoTextArea(this.search_results[0].sn); } } else { this.debouncedFilter(ev.target);