Save chat scroll position when user input overflows the line

This commit is contained in:
Cohee 2023-09-13 00:51:21 +03:00
parent 66ec17620f
commit c0e5d7efae
3 changed files with 11 additions and 6 deletions

View File

@ -4436,13 +4436,14 @@ async function read_avatar_load(input) {
}); });
$(".mes").each(async function () { $(".mes").each(async function () {
if ($(this).attr("is_system") == 'true') { const nameMatch = $(this).attr("ch_name") == formData.get('ch_name');
if ($(this).attr("is_system") == 'true' && !nameMatch) {
return; return;
} }
if ($(this).attr("is_user") == 'true') { if ($(this).attr("is_user") == 'true') {
return; return;
} }
if ($(this).attr("ch_name") == formData.get('ch_name')) { if (nameMatch) {
const previewSrc = $("#avatar_load_preview").attr("src"); const previewSrc = $("#avatar_load_preview").attr("src");
const avatar = $(this).find(".avatar img"); const avatar = $(this).find(".avatar img");
avatar.attr('src', default_avatar); avatar.attr('src', default_avatar);

View File

@ -863,8 +863,12 @@ export function initRossMods() {
//this makes the chat input text area resize vertically to match the text size (limited by CSS at 50% window height) //this makes the chat input text area resize vertically to match the text size (limited by CSS at 50% window height)
$('#send_textarea').on('input', function () { $('#send_textarea').on('input', function () {
const chatBlock = $('#chat');
const originalScrollBottom = chatBlock[0].scrollHeight - (chatBlock.scrollTop() + chatBlock.outerHeight());
this.style.height = window.getComputedStyle(this).getPropertyValue('min-height'); this.style.height = window.getComputedStyle(this).getPropertyValue('min-height');
this.style.height = (this.scrollHeight) + 'px'; this.style.height = (this.scrollHeight) + 'px';
const newScrollTop = chatBlock[0].scrollHeight - (chatBlock.outerHeight() + originalScrollBottom);
chatBlock.scrollTop(newScrollTop);
}); });
//Regenerate if user swipes on the last mesage in chat //Regenerate if user swipes on the last mesage in chat

View File

@ -62,11 +62,11 @@ const generateDebounced = debounce(() => generateHypeBot(), 500);
* @param {string} text Text to set * @param {string} text Text to set
*/ */
function setHypeBotText(text) { function setHypeBotText(text) {
const blockA = $('#chat'); const chatBlock = $('#chat');
var originalScrollBottom = blockA[0].scrollHeight - (blockA.scrollTop() + blockA.outerHeight()); const originalScrollBottom = chatBlock[0].scrollHeight - (chatBlock.scrollTop() + chatBlock.outerHeight());
hypeBotBar.html(DOMPurify.sanitize(text)); hypeBotBar.html(DOMPurify.sanitize(text));
var newScrollTop = blockA[0].scrollHeight - (blockA.outerHeight() + originalScrollBottom); const newScrollTop = chatBlock[0].scrollHeight - (chatBlock.outerHeight() + originalScrollBottom);
blockA.scrollTop(newScrollTop); chatBlock.scrollTop(newScrollTop);
} }
/** /**