diff --git a/public/script.js b/public/script.js index 277453e37..f2d87bea5 100644 --- a/public/script.js +++ b/public/script.js @@ -846,7 +846,7 @@ async function replaceCurrentChat() { function printMessages() { chat.forEach(function (item, i, arr) { - addOneMessage(item); + addOneMessage(item, { scroll: i === arr.length - 1 }); }); } @@ -916,7 +916,7 @@ function appendImageToMessage(mes, messageElement) { } } -function addOneMessage(mes, type = "normal", insertAfter = null) { +function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true } = {}) { var messageText = mes["mes"]; var characterName = name1; var avatarImg = "User Avatars/" + user_avatar; @@ -1000,7 +1000,7 @@ function addOneMessage(mes, type = "normal", insertAfter = null) { */ // Don't scroll if not inserting last - if (!insertAfter) { + if (!insertAfter && scroll) { $('#chat .mes').last().addClass('last_mes'); $('#chat .mes').eq(-2).removeClass('last_mes'); @@ -2224,7 +2224,7 @@ function saveReply(type, getMessage, this_mes_is_name) { //console.log(getMessage); chat[chat.length - 1]['mes'] = getMessage; // console.log('runGenerate calls addOneMessage for swipe'); - addOneMessage(chat[chat.length - 1], 'swipe'); + addOneMessage(chat[chat.length - 1], { type: 'swipe' }); } else { chat[chat.length - 1]['mes'] = getMessage; } @@ -3574,7 +3574,7 @@ $(document).ready(function () { } else { //console.log('showing previously generated swipe candidate, or "..."'); //console.log('onclick right swipe calling addOneMessage'); - addOneMessage(chat[chat.length - 1], 'swipe'); + addOneMessage(chat[chat.length - 1], { type: 'swipe' }); } let new_height = this_mes_div_height - (this_mes_block_height - this_mes_block[0].scrollHeight); if (new_height < 103) new_height = 103; @@ -3682,7 +3682,7 @@ $(document).ready(function () { complete: function () { const is_animation_scroll = ($('#chat').scrollTop() >= ($('#chat').prop("scrollHeight") - $('#chat').outerHeight()) - 10); //console.log('on left swipe click calling addOneMessage'); - addOneMessage(chat[chat.length - 1], 'swipe'); + addOneMessage(chat[chat.length - 1], { type: 'swipe' }); let new_height = this_mes_div_height - (this_mes_block_height - this_mes_block[0].scrollHeight); if (new_height < 103) new_height = 103; this_mes_div.animate({ height: new_height + 'px' }, { @@ -4826,7 +4826,7 @@ $(document).ready(function () { clone.mes = $(this).closest(".mes").find('.edit_textarea').val().trim(); chat.splice(Number(this_edit_mes_id) + 1, 0, clone); - addOneMessage(clone, 'normal', this_edit_mes_id); + addOneMessage(clone, { insertAfter: this_edit_mes_id }); updateViewMessageIds(); saveChatConditional();