Place cursor at the end when correcting a message
This commit is contained in:
parent
08dce556f9
commit
d852721933
@ -1012,21 +1012,23 @@
|
||||
|
||||
insertIntoTextArea (value, replace=false, correcting=false) {
|
||||
const textarea = this.el.querySelector('.chat-textarea');
|
||||
if (correcting) {
|
||||
u.addClass('correcting', textarea);
|
||||
} else {
|
||||
u.removeClass('correcting', textarea);
|
||||
}
|
||||
if (replace) {
|
||||
textarea.value = '';
|
||||
textarea.value = value;
|
||||
} else {
|
||||
let existing = textarea.value;
|
||||
if (existing && (existing[existing.length-1] !== ' ')) {
|
||||
existing = existing + ' ';
|
||||
}
|
||||
textarea.value = '';
|
||||
textarea.value = existing+value+' ';
|
||||
}
|
||||
if (correcting) {
|
||||
u.addClass('correcting', textarea);
|
||||
} else {
|
||||
u.removeClass('correcting', textarea);
|
||||
}
|
||||
textarea.focus()
|
||||
u.putCurserAtEnd(textarea);
|
||||
},
|
||||
|
||||
createEmojiPicker () {
|
||||
|
@ -849,6 +849,19 @@
|
||||
return result;
|
||||
};
|
||||
|
||||
u.putCurserAtEnd = function (textarea) {
|
||||
if (textarea !== document.activeElement) {
|
||||
textarea.focus();
|
||||
}
|
||||
// Double the length because Opera is inconsistent about whether a carriage return is one character or two.
|
||||
const len = textarea.value.length * 2;
|
||||
// Timeout seems to be required for Blink
|
||||
setTimeout(() => textarea.setSelectionRange(len, len), 1);
|
||||
// Scroll to the bottom, in case we're in a tall textarea
|
||||
// (Necessary for Firefox and Chrome)
|
||||
this.scrollTop = 999999;
|
||||
};
|
||||
|
||||
u.getUniqueId = function () {
|
||||
return 'xxxxxxxx-xxxx'.replace(/[x]/g, function(c) {
|
||||
var r = Math.random() * 16 | 0,
|
||||
|
Loading…
Reference in New Issue
Block a user