From 4c635f38c22597e9f1c1e68c05df0aff1b48247f Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 13 Feb 2015 01:46:11 +0300 Subject: [PATCH] Improved insert emoji --- app/js/message_composer.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/js/message_composer.js b/app/js/message_composer.js index 5239cf82..ff7ec906 100644 --- a/app/js/message_composer.js +++ b/app/js/message_composer.js @@ -738,29 +738,27 @@ MessageComposer.prototype.onEmojiSelected = function (code, autocomplete) { if (window.getSelection) { var sel = window.getSelection(); if (sel.getRangeAt && sel.rangeCount) { - var range = sel.getRangeAt(0); - range.deleteContents(); var el = document.createElement('div'); el.innerHTML = html; - var frag = document.createDocumentFragment(), node, lastNode; - while ( (node = el.firstChild) ) { - lastNode = frag.appendChild(node); - } - range.insertNode(frag); + var node = el.firstChild; + var range = sel.getRangeAt(0); + range.deleteContents(); + range.insertNode(document.createTextNode(' ')); + range.insertNode(node); + range.setStart(node, 0); - if (lastNode) { - range = range.cloneRange(); - range.setStartAfter(lastNode); + setTimeout(function() { + range = document.createRange(); + range.setStartAfter(node); range.collapse(true); sel.removeAllRanges(); sel.addRange(range); - } + }, 0); } } else if (document.selection && document.selection.type != 'Control') { document.selection.createRange().pasteHTML(html); } - // document.execCommand('insertHTML', false, html); } } else {