From 76b15f1971ddbf2e984c1fe72ac60e6d306dbfa5 Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Thu, 28 Sep 2017 01:00:03 +0200
Subject: [PATCH] Fix wrong emoji names & issues with emoji keyboard on while
 using :emoji_name:

---
 Resources/Plugins/emoji-keyboard/browser.js | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/Resources/Plugins/emoji-keyboard/browser.js b/Resources/Plugins/emoji-keyboard/browser.js
index 19be2e4a..1476c9b9 100644
--- a/Resources/Plugins/emoji-keyboard/browser.js
+++ b/Resources/Plugins/emoji-keyboard/browser.js
@@ -84,7 +84,7 @@ enabled(){
     if (refocus){
       this.composeInput.focus();
       
-      if (lastEmojiKeyword){
+      if (lastEmojiKeyword && lastEmojiPosition === 0){
         document.execCommand("insertText", false, lastEmojiKeyword);
       }
     }
@@ -323,11 +323,13 @@ enabled(){
         let foundEmoji;
         
         for(let array of [ me.emojiData1, me.emojiData2[me.selectedSkinTone], me.emojiData3 ]){
-          if (foundIndex >= array.length){
-            foundIndex -= array.length;
+          let realArray = array.filter(ele => ele !== "___");
+          
+          if (foundIndex >= realArray.length){
+            foundIndex -= realArray.length;
           }
           else{
-            foundEmoji = array[foundIndex];
+            foundEmoji = realArray[foundIndex];
             break;
           }
         }
@@ -350,8 +352,11 @@ enabled(){
         ele[0].selectionEnd = ele[0].selectionStart = firstColon;
         ele.trigger("change");
         
-        $(".emoji-keyboard-popup-btn").click();
-        $(".emoji-keyboard-search").children("input").focus();
+        if (!me.currentKeyboard){
+          $(".emoji-keyboard-popup-btn").click();
+        }
+        
+        $(".emoji-keyboard-search").children("input").focus().val("");
         document.execCommand("insertText", false, keywords.join(" "));
       }
     }