From a1a9fd073cafba170f600b7a5db6476d9c1625a6 Mon Sep 17 00:00:00 2001 From: marlon-erler Date: Tue, 9 Jul 2024 18:35:48 +0200 Subject: [PATCH] prevent scrolling to new message when the user scrolled up --- dist/index.js | 7 ++++++- src/Views/threadView.tsx | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2c63a490..889cc0e9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -453,6 +453,7 @@ isoDate: (/* @__PURE__ */ new Date()).toISOString() }; const messageString = JSON.stringify(messageObject); + console.log(messageString); UDN.sendMessage(joinedChannelName, messageString); this.composingMessage.value = ""; }; @@ -908,7 +909,11 @@ "children:append": [chat.messages, messageConverter] } ); - chat.messages.handleAddition(() => listElement.scrollTop = listElement.scrollHeight); + chat.messages.handleAddition(() => { + const scrollFromBottom = listElement.scrollHeight - (listElement.scrollTop + listElement.offsetHeight); + if (scrollFromBottom > 400) return; + listElement.scrollTop = listElement.scrollHeight; + }); return listElement; } diff --git a/src/Views/threadView.tsx b/src/Views/threadView.tsx index 59e4166d..8bde7c32 100644 --- a/src/Views/threadView.tsx +++ b/src/Views/threadView.tsx @@ -65,6 +65,13 @@ export function ThreadView(chat: Chat) { children:append={[chat.messages, messageConverter]} > ); - chat.messages.handleAddition(() => listElement.scrollTop = listElement.scrollHeight); + chat.messages.handleAddition(() => { + const scrollFromBottom = + listElement.scrollHeight - + (listElement.scrollTop + listElement.offsetHeight); + if (scrollFromBottom > 400) return; + + listElement.scrollTop = listElement.scrollHeight; + }); return listElement; }