Fix selection bug with IE11 in text editor
This commit is contained in:
parent
700e226ba8
commit
858def555f
File diff suppressed because one or more lines are too long
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in New Issue