diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp
index 889940cf9abe00d46a1e79c1881da6c9ec1e748f..168c260c7d46f89e14cdd0ef759a532fe1fb5c00 100644
--- a/indra/llui/lltexteditor.cpp
+++ b/indra/llui/lltexteditor.cpp
@@ -676,6 +676,21 @@ void LLTextEditor::selectByCursorPosition(S32 prev_cursor_pos, S32 next_cursor_p
 	endSelection();
 }
 
+void LLTextEditor::handleEmojiCommit(const LLWString& wstr)
+{
+	LLWString wtext(getWText()); S32 shortCodePos;
+	if (LLEmojiHelper::isCursorInEmojiCode(wtext, mCursorPos, &shortCodePos))
+	{
+		remove(shortCodePos, mCursorPos - shortCodePos, true);
+
+		auto styleParams = LLStyle::Params();
+		styleParams.font = LLFontGL::getFontEmoji();
+		insert(shortCodePos, wstr, false, new LLEmojiTextSegment(new LLStyle(styleParams), shortCodePos, shortCodePos + wstr.size(), *this));
+
+		setCursorPos(shortCodePos + 1);
+	}
+}
+
 BOOL LLTextEditor::handleMouseDown(S32 x, S32 y, MASK mask)
 {
 	BOOL	handled = FALSE;
@@ -1147,9 +1162,9 @@ void LLTextEditor::addChar(llwchar wc)
 		LLWString wtext(getWText()); S32 shortCodePos;
 		if (LLEmojiHelper::isCursorInEmojiCode(wtext, mCursorPos, &shortCodePos))
 		{
-			const LLRect cursorRect = getLocalRectFromDocIndex(mCursorPos);
-			const LLWString shortCode = wtext.substr(shortCodePos, mCursorPos);
-			LLEmojiHelper::instance().showHelper(this, cursorRect.mLeft, cursorRect.mTop, wstring_to_utf8str(shortCode));
+			const LLRect cursorRect = getLocalRectFromDocIndex(mCursorPos - 1);
+			const LLWString shortCode = wtext.substr(shortCodePos, mCursorPos - shortCodePos);
+			LLEmojiHelper::instance().showHelper(this, cursorRect.mLeft, cursorRect.mTop, wstring_to_utf8str(shortCode), std::bind(&LLTextEditor::handleEmojiCommit, this, std::placeholders::_1));
 		}
 	}
 
diff --git a/indra/llui/lltexteditor.h b/indra/llui/lltexteditor.h
index 04910b6f68aacf9d87be6453e76fe9c8da6b3cc7..4c8175a28655866e8d2e7747ebbffac00e07fb2d 100644
--- a/indra/llui/lltexteditor.h
+++ b/indra/llui/lltexteditor.h
@@ -92,6 +92,8 @@ class LLTextEditor :
 
 	static S32		spacesPerTab();
 
+	        void    handleEmojiCommit(const LLWString& wstr);
+
 	// mousehandler overrides
 	virtual BOOL	handleMouseDown(S32 x, S32 y, MASK mask);
 	virtual BOOL	handleMouseUp(S32 x, S32 y, MASK mask);