Fix selection bug with IE11 in text editor

This commit is contained in:
Frederic Guillot 2016-11-30 21:05:57 -05:00
parent 700e226ba8
commit 858def555f
No known key found for this signature in database
GPG Key ID: 92D77191BA7FBC99
2 changed files with 16 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@ -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');