(js) Restore caret position in message editor

Fixes #4517
This commit is contained in:
Francis Lachapelle
2018-08-17 16:31:50 -04:00
parent e5d3c5fa33
commit f0b4e1b719
7 changed files with 161 additions and 9 deletions
+27
View File
@@ -509,6 +509,33 @@ Date.prototype.format = function(localeProvider, format) {
return date.join('');
};
Element.prototype.setCaretTo = function(pos) {
if (this.setSelectionRange) { // For Mozilla and Safari
this.focus();
this.setSelectionRange(pos, pos);
}
else if (this.createTextRange) { // For IE
var range = this.createTextRange();
range.move('character', pos);
range.select();
}
};
Element.prototype.selectText = function(start, end) {
if (this.setSelectionRange) { // For Mozilla and Safari
this.setSelectionRange(start, end);
}
else if (this.createTextRange) { // For IE
var textRange = this.createTextRange();
textRange.moveStart('character', start);
textRange.moveEnd('character', end-element.value.length);
textRange.select();
}
else {
this.select();
}
};
/* Functions */
function l() {