emoji-view: insert partially matched emoji on enter

if it's the only search hit.
This commit is contained in:
JC Brand 2019-09-05 16:22:57 +02:00
parent f52ade1193
commit dfafbefb71

View File

@ -239,6 +239,15 @@ converse.plugins.add('converse-emoji-views', {
sizzle('.emoji-picker', this.el).forEach(a => this.observer.observe(a)); 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) { onKeyDown (ev) {
if (ev.keyCode === _converse.keycodes.TAB) { if (ev.keyCode === _converse.keycodes.TAB) {
ev.preventDefault(); ev.preventDefault();
@ -250,12 +259,9 @@ converse.plugins.add('converse-emoji-views', {
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
if (_converse.emoji_shortnames.includes(ev.target.value)) { if (_converse.emoji_shortnames.includes(ev.target.value)) {
const replace = this.model.get('autocompleting'); this.insertIntoTextArea(ev.target.value);
const position = this.model.get('position'); } else if (this.search_results.length === 1) {
this.model.set({'autocompleting': null, 'position': null}); this.insertIntoTextArea(this.search_results[0].sn);
this.chatview.insertIntoTextArea(ev.target.value, replace, false, position);
this.chatview.emoji_dropdown.toggle();
this.filter('', true);
} }
} else { } else {
this.debouncedFilter(ev.target); this.debouncedFilter(ev.target);