Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: improve jumpToMessage scrolling #4204

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Update local help (2024-10-02) #4165
- trim whitepaces when reading from clipboard in qr code reader #4169
- load chat lists faster (the chat list on the main screen, "Forward to..." dialog, etc)
- when jumping to message, don't scroll the message list if the message is already in view #4204

### Fixed
- fix that you can not click header button in dialog when they are on top of the navbar #4093
Expand Down
15 changes: 14 additions & 1 deletion packages/frontend/scss/message/_message-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,20 @@
margin: 10px 0px;

li {
margin-bottom: 10px;
$margin-bottom: 10px;
margin-bottom: $margin-bottom;
// This is so that when we `scrollIntoView()` the last message
// in the chat, its margin is also scrolled into view.
// Otherwise only the visible part of the message would get scrolled
// into view, resulting in the message list not getting
// scrolled all the way to the bottom,
// resulting in the message list not not getting scrolled to the
// bottom when another message arrives.
scroll-margin-bottom: $margin-bottom;
// And this is purely cosmetic. For scrolling to a message
// that is above the visible area.
scroll-margin-top: $margin-bottom / 2;

min-width: 200px;

&::after {
Expand Down
12 changes: 11 additions & 1 deletion packages/frontend/src/components/message/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,17 @@ export default function MessageList({ accountId, chat, refComposer }: Props) {
)
}

domElement.scrollIntoView()
domElement.scrollIntoView({
// "nearest" so as to not scroll if the message is already in view.
// Otherwise we'd try to scroll in such a way that the message
// is at the very top of the messages list.
// This would not be nice for the Ctrl + Down shortcut
// (when quoting a message that a bit far up),
// or when highlighting the reply that is already in view.
block: 'nearest',
inline: 'nearest',
// behavior:
})

if (scrollTo.highlight === true) {
// Trigger highlight animation
Expand Down
Loading