Preserve chat and journal position while scrolling history

This commit is contained in:
coyotte508 2026-09-27 10:05:36 +02:00
commit 212b56cd3c
6 changed files with 53 additions and 4 deletions

View file

@ -0,0 +1,42 @@
diff --git a/dist/chat-viewport.js b/dist/chat-viewport.js
index 84fdef2bdf411584349a54362663a379d6778808..e322c2a25c0456ada442bbbff2d49494d0db952b 100644
--- a/dist/chat-viewport.js
+++ b/dist/chat-viewport.js
@@ -74,6 +74,11 @@ export function bindChatViewport(list, options) {
chat.markRead(latest.dataset.messageId);
}
}
+ function updateFollowing() {
+ if (list.clientHeight && initialized && list.scrollTop !== programmedScroll) {
+ following = list.scrollHeight - list.scrollTop - list.clientHeight <= 1;
+ }
+ }
function refresh() {
if (disposed || frame !== undefined) {
return;
@@ -81,11 +86,13 @@ export function bindChatViewport(list, options) {
frame = win.requestAnimationFrame(() => {
frame = undefined;
if (list.clientHeight && chat.snapshot.open && (options.isVisible?.() ?? true)) {
+ // Observers can run before the scroll event from a small wheel or touch movement.
+ updateFollowing();
if (scrollToUnread) {
const row = rows().find((element) => chat.snapshot.unreadIds.includes(element.dataset.messageId ?? ""));
if (row) {
list.scrollTop += row.getBoundingClientRect().top - list.getBoundingClientRect().top;
- following = list.scrollHeight - list.scrollTop - list.clientHeight < 32;
+ following = list.scrollHeight - list.scrollTop - list.clientHeight <= 1;
}
else {
following = true;
@@ -103,9 +110,7 @@ export function bindChatViewport(list, options) {
});
}
function scroll() {
- if (list.clientHeight && initialized && list.scrollTop !== programmedScroll) {
- following = list.scrollHeight - list.scrollTop - list.clientHeight < 32;
- }
+ updateFollowing();
refresh();
}
const resize = new ResizeObserver(refresh);

1
patches/README.md Normal file
View file

@ -0,0 +1 @@
The protocol 0.6.1 patch backports the [shared chat scrolling fix](https://codeberg.org/boardgamers/boardgamers/commit/7b4e1ff6). It prevents slow wheel and touch gestures from snapping back to the newest message. Remove the patch when upgrading to a protocol release containing that fix.

7
pnpm-lock.yaml generated
View file

@ -6,6 +6,9 @@ settings:
packageExtensionsChecksum: sha256-00qAjbZKW5ZUQ9vzlY/TpeXMvkYJise4VKJxePABdVI=
patchedDependencies:
'@boardgamers/protocol@0.6.1': 4ec4a210cf846eebd6d902b2952c029dbcde5ed288f88dba1f9362a8a9caa953
importers:
.:
devDependencies:
@ -87,7 +90,7 @@ importers:
dependencies:
'@boardgamers/protocol':
specifier: 0.6.1
version: 0.6.1
version: 0.6.1(patch_hash=4ec4a210cf846eebd6d902b2952c029dbcde5ed288f88dba1f9362a8a9caa953)
container-engine:
specifier: workspace:../engine
version: link:../engine
@ -11586,7 +11589,7 @@ snapshots:
'@babel/helper-string-parser': 7.29.7
'@babel/helper-validator-identifier': 7.29.7
'@boardgamers/protocol@0.6.1':
'@boardgamers/protocol@0.6.1(patch_hash=4ec4a210cf846eebd6d902b2952c029dbcde5ed288f88dba1f9362a8a9caa953)':
dependencies:
zod: 4.6.2

View file

@ -29,3 +29,6 @@ packageExtensions:
'@vue/cli-plugin-typescript':
dependencies:
'@vue/compiler-sfc': ^3.5.41
patchedDependencies:
'@boardgamers/protocol@0.6.1': patches/@boardgamers__protocol@0.6.1.patch

View file

@ -1,6 +1,6 @@
{
"name": "container-viewer",
"version": "2.0.11",
"version": "2.0.12",
"repository": {
"type": "git",
"url": "git+https://github.com/boardgamers/container.git",

View file

@ -40,7 +40,7 @@ export default class InlineLog extends Vue {
onScroll() {
const feed = this.$refs.feed as HTMLElement;
if (!feed.clientHeight) return;
this.follow = feed.scrollHeight - feed.scrollTop - feed.clientHeight < 32;
this.follow = feed.scrollHeight - feed.scrollTop - feed.clientHeight <= 1;
}
}
</script>