CRM-20418: Make token insertion work correctly when wysiwig is not loaded on Message...
authorNoah Miller <nm@lemnisc.us>
Thu, 11 May 2017 16:42:43 +0000 (11:42 -0500)
committerNoah Miller <nm@lemnisc.us>
Thu, 11 May 2017 16:50:00 +0000 (11:50 -0500)
js/wysiwyg/crm.wysiwyg.js

index 743fb5e3636a96ccab6b9f8b253da06f8a648575..f80b6e3388d68acaef420dbb4994a9d324c554ca 100644 (file)
     },
     // 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');