From e815b31bda3b9cc04f72f8b8ad20768b0bd618ba Mon Sep 17 00:00:00 2001 From: Noah Miller Date: Thu, 11 May 2017 11:42:43 -0500 Subject: [PATCH] CRM-20418: Make token insertion work correctly when wysiwig is not loaded on Message Template edit --- js/wysiwyg/crm.wysiwyg.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/js/wysiwyg/crm.wysiwyg.js b/js/wysiwyg/crm.wysiwyg.js index 743fb5e363..f80b6e3388 100644 --- a/js/wysiwyg/crm.wysiwyg.js +++ b/js/wysiwyg/crm.wysiwyg.js @@ -34,12 +34,13 @@ }, // Fallback function to use when a wysiwyg has not been initialized _insertIntoTextarea: function(item, text) { - itemObj = $(item); + var itemObj = $(item); var origVal = itemObj.val(); - var origPos = itemObj[0].selectionStart; - var newVal = origVal.substring(0, origPos) + text + origVal.substring(origPos, origPos.length); + var origStart = itemObj[0].selectionStart; + var origEnd = itemObj[0].selectionEnd; + var newVal = origVal.substring(0, origStart) + text + origVal.substring(origEnd); itemObj.val(newVal); - var newPos = (origPos + text.length); + var newPos = (origStart + text.length); itemObj[0].selectionStart = newPos; itemObj[0].selectionEnd = newPos; itemObj.triggerHandler('change'); -- 2.25.1