diff options
Diffstat (limited to 'assets/js/components')
-rw-r--r-- | assets/js/components/text-editor.js | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/assets/js/components/text-editor.js b/assets/js/components/text-editor.js index 8b601c01..f94b72f8 100644 --- a/assets/js/components/text-editor.js +++ b/assets/js/components/text-editor.js @@ -118,10 +118,21 @@ KB.component('text-editor', function (containerElement, options) { function insertText(replacedText) { var result = false; - selectionStart = textarea.selectionStart; - selectionEnd = textarea.selectionEnd; textarea.focus(); + // Fix issue with IE11 (last line with wrong position) + if (textarea.value.length < textarea.selectionStart) { + selectionStart = textarea.value.length; + } else { + selectionStart = textarea.selectionStart; + } + + if (textarea.selectionStart === textarea.selectionEnd) { + selectionEnd = selectionStart; + } else { + selectionEnd = textarea.selectionEnd; + } + if (document.queryCommandSupported('insertText')) { result = document.execCommand('insertText', false, replacedText); } @@ -131,7 +142,7 @@ KB.component('text-editor', function (containerElement, options) { document.execCommand('ms-beginUndoUnit'); } catch (error) {} - textarea.value = replaceTextRange(textarea.value, textarea.selectionStart, textarea.selectionEnd, replacedText); + textarea.value = replaceTextRange(textarea.value, selectionStart, textarea.selectionEnd, replacedText); try { document.execCommand('ms-endUndoUnit'); |